1001.害死人不偿命的(3n+1)猜想

题目截图:

 

思路:

  简单模拟。具体见另一篇博客

代码:

 1 /*
 2     1001.害死人不偿命的(3n+1)猜想 
 3 */
 4 
 5 #include <stdio.h>
 6 #include <string.h>
 7 #include <math.h>
 8 #include <stdlib.h>
 9 #include <time.h>
10 
11 int main() {
12     int n, cnt=0;            // cnt 步数 
13     scanf("%d", &n);
14     while(n != 1) {
15         if(n&1) {            // 奇数 
16             n = (3*n+1)/2;
17         } else {            // 偶数 
18             n /= 2;
19         }
20         cnt++;
21     } 
22     printf("%d", cnt);
23 
24     return 0;
25 }
原文地址:https://www.cnblogs.com/coderJiebao/p/PAT201.html