
Given a positive integer n, repeatedly apply: divide by 2 if even, multiply by 3 and add 1 if odd. Print all values until n becomes 1.
long long.
- Simulation
#include <bits/stdc++.h> using namespace std; int main() { long long n; cin >> n; while (n != 1) { cout << n << " "; if (n % 2 == 0) n /= 2; else n = 3 * n + 1; } cout << 1 << "\n"; return 0; }