Advertisement
skb50bd

3n + 1

Jun 30th, 2015
352
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.25 KB | None | 0 0
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. int main () {
  5.     long long int n;
  6.     cin >> n;
  7.     while (true) {
  8.         cout << n << " ";
  9.         if (n == 1) break;
  10.         n = (n % 2) ? 3 * n + 1 : n / 2;
  11.     }
  12.     cout << endl;
  13.     return 0;
  14. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement