解题思路:
3N+1问题
只是需要输出过程而已。。
注意事项:
炉石传说真尼玛好玩!!!
参考代码:
#include<iostream> using namespace std; int main() { int n; while (cin >> n) { while (n != 1) { if (n % 2 == 0) { cout << n << "/2=" << n / 2 << endl; n /= 2; } else { cout << n << "*3+1=" << n * 3 + 1 << endl; n = n * 3 + 1; } } } return 0; }
0.0分
6 人评分