csansoon

P3.09 P80660 The sequence of Collatz

Oct 3rd, 2018
141
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.26 KB | None | 0 0
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. int main() {
  5.     int n, s;
  6.     while (cin >> n) {
  7.         s=0;
  8.         while (n!=1) {
  9.             if (n%2==0) n/=2;
  10.             else {n*=3;n++;}
  11.             s++;
  12.         }
  13.         cout << s << endl;
  14.     }
  15. }
Advertisement
Add Comment
Please, Sign In to add comment