提交时间:2026-06-02 15:39:34

运行 ID: 89352

#include <iostream> using namespace std; int main() { int n; cin >> n; while (n != 1) { if (n % 2 == 0) { // 偶数:除以2 cout << n << "/2=" << n / 2 << endl; n = n / 2; // 更新n为新值 } else { // 奇数:乘3加1 cout << n << "*3+1=" << n * 3 + 1 << endl; n = n * 3 + 1; // 更新n为新值 } } cout << "end" << endl; // 注意:小写 end! return 0; }