#includeusing namespace std; int main() { int n,count = 0; cin >> n; while(n > 1) { if(n % 2) { n = (3 * n + 1) / 2; } else { n /= 2; } count++; } cout << count; return 0; }
这道题较为简单,先设置一个计数器,
之后在while循环内嵌套if判断语句即可

#includeusing namespace std; int main() { int n,count = 0; cin >> n; while(n > 1) { if(n % 2) { n = (3 * n + 1) / 2; } else { n /= 2; } count++; } cout << count; return 0; }
这道题较为简单,先设置一个计数器,
之后在while循环内嵌套if判断语句即可