fork download
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. int main() {
  5. long long n;
  6. cin >> n;
  7.  
  8. while (n != 1) {
  9. cout << n << " ";
  10.  
  11. if (n % 2 == 0) n /= 2;
  12. else n = n * 3 + 1;
  13. }
  14.  
  15. cout << n;
  16.  
  17.  
  18. return 0;
  19. }
Success #stdin #stdout 0s 5316KB
stdin
3
stdout
3 10 5 16 8 4 2 1