PTA 乙级 1001 害死人不偿命的(3n+1)猜想 (15分) C/C++
C
1 #include<stdio.h> 2 3 int main(){ 4 int n = 0; 5 int num = 0; 6 //printf("请输入一个不超过1000的正整数:"); 7 scanf("%d", &num); 8 while(num != 1){ 9 if(num%2 == 0){ 10 num = num / 2; 11 n++; 12 }else{ 13 num = (3*num + 1) / 2; 14 // printf("%d\n",num)]; 15 n++; 16 } 17 } 18 printf("%d\n", n); 19 return 0; 20 21 }
默默地一点点变强,细节决定成败