Advertisement
Rehan_Rahman26

3n+1__UVA

Oct 24th, 2021
1,027
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.61 KB | None | 0 0
  1. #include <iostream>
  2. #include <cstdio>
  3.  
  4. using namespace std;
  5.  
  6. int main ()
  7. {
  8.     int i, j;
  9.     while ((cin>>i>>j))
  10.     {
  11.         int i1 = i;
  12.         int j1 = j;
  13.  
  14.         if ( i > j ) swap (i, j);
  15.  
  16.         int mcl= 0,cl;
  17.         while ( i <= j )
  18.         {
  19.             cl = 1;
  20.             unsigned int n=i;
  21.             while ( n != 1 )
  22.             {
  23.                 if ( n % 2 == 1 ) n = 3 * n + 1;
  24.                 else n = n/2;
  25.                 cl++;
  26.             }
  27.  
  28.            mcl = max(mcl,cl);
  29.  
  30.             i++;
  31.         }
  32.  
  33.         cout<<i1<<" "<<j1<<" "<<mcl<<endl;
  34.     }
  35.  
  36.     return 0;
  37. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement