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 5288KB
stdin
2121
stdout
2121 6364 3182 1591 4774 2387 7162 3581 10744 5372 2686 1343 4030 2015 6046 3023 9070 4535 13606 6803 20410 10205 30616 15308 7654 3827 11482 5741 17224 8612 4306 2153 6460 3230 1615 4846 2423 7270 3635 10906 5453 16360 8180 4090 2045 6136 3068 1534 767 2302 1151 3454 1727 5182 2591 7774 3887 11662 5831 17494 8747 26242 13121 39364 19682 9841 29524 14762 7381 22144 11072 5536 2768 1384 692 346 173 520 260 130 65 196 98 49 148 74 37 112 56 28 14 7 22 11 34 17 52 26 13 40 20 10 5 16 8 4 2