题解 | #xxx定律#
xxx定律
https://www.nowcoder.com/practice/75c189249d6145cfa33cd53edae6afc8
#include<bits/stdc++.h>
using namespace std;
int main() {
int n;
while (cin >> n) {//while处理多个case
int count = 0;//count变量用于计数
while (n != 1) {
if (n % 2 == 0) {//n为偶数
n /= 2;
count++;
} else {//n为奇数
n = (3 * n + 1) / 2;
count++;
}
}
cout << count << endl;
}
}
上海得物信息集团有限公司公司福利 1166人发布