Advertisement
Josif_tepe

Untitled

Sep 30th, 2022
818
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.49 KB | None | 0 0
  1. #include <iostream>
  2.  
  3. using namespace std;
  4.  
  5. int main()
  6. {
  7.     long long n;
  8.     cin >> n;
  9.     if (n == 1)
  10.     {
  11.         cout << n << " ";
  12.         return 0;
  13.     }
  14.     cout << n << " ";
  15.     for(long long i = 0; i <= 20000000; i++)
  16.     {
  17.         if(n % 2 == 1)
  18.         {
  19.             n *= 3;
  20.             n += 1;
  21.             cout << n << " ";
  22.         }
  23.  
  24.         else {n /= 2;
  25.         cout << n << " ";}
  26.  
  27.         if (n == 1)
  28.         {
  29.             break;
  30.         }
  31.  
  32.     }
  33.  
  34. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement