题解 | xxx定律
xxx定律
https://www.nowcoder.com/practice/75c189249d6145cfa33cd53edae6afc8
#include <iostream>
using namespace std;
int xxxlaw(int n) {
int count = 0;
while (1 != n) {
if (0 == n % 2) {
n = n / 2;
} else {
n = 3 * n + 1;
n = n / 2;
}
count++;
}
return count;
}
int main() {
int n;
while (cin >> n) {
cout << xxxlaw(n) << endl;
}
return 0;
}
#考研##复试练习#2025考研复试 文章被收录于专栏
复试ing,努力中。。。
上海得物信息集团有限公司公司福利 1164人发布
