weird_algorithm.cpp (218B)
1 #include <bits/stdc++.h> 2 3 using namespace std; 4 5 void solve() 6 { 7 long n; 8 cin >> n; 9 while (n != 1) { 10 cout << n << " "; 11 if (n % 2) 12 n = 3 * n + 1; 13 else 14 n >>= 1; 15 } 16 cout << "1\n"; 17 } 18 19 int main() 20 { 21 solve(); 22 }