fork download
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3.  
  4. int main() {
  5.  
  6. int n;
  7. cin >> n;
  8. int res = n;
  9. while (res != 1) {
  10. cout << res << " ";
  11. if (res % 2 == 0) {
  12. res /= 2;
  13. } else {
  14. res = res * 3 + 1;
  15. }
  16. }
  17. }
Success #stdin #stdout 0.01s 5328KB
stdin
123
stdout
123 370 185 556 278 139 418 209 628 314 157 472 236 118 59 178 89 268 134 67 202 101 304 152 76 38 19 58 29 88 44 22 11 34 17 52 26 13 40 20 10 5 16 8 4 2