题解 | xxx定律
#include <iostream> using namespace std; int main() { int a; while (cin >> a ) { int res = 0; while(a!=1){ if(a%2== 0) { //偶数 a /= 2; }else{ //奇数 a = (3*a + 1)/2; } res++; } cout<<res; } }
#include <iostream> using namespace std; int main() { int a; while (cin >> a ) { int res = 0; while(a!=1){ if(a%2== 0) { //偶数 a /= 2; }else{ //奇数 a = (3*a + 1)/2; } res++; } cout<<res; } }
相关推荐