Advertisement
backstreetimrul

uva 100

Dec 14th, 2017
98
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.77 KB | None | 0 0
  1. #include<iostream>
  2. using namespace std;
  3. int main()
  4. {
  5.     int i,j;
  6.  
  7.     for(;;)
  8.     {
  9.         cin>>i>>j;
  10.         cout<<i<<" "<<j<<" ";
  11.  
  12.         if(i>j)
  13.         {
  14.             swap(i,j);
  15.         }
  16.  
  17.         int max=0;
  18.         int count=1;
  19.         int n;
  20.  
  21.         for(int k=i;k<=j;k++)
  22.         {
  23.             n=k;
  24.  
  25.             while(n!=1)
  26.             {
  27.                 if(n%2==0)
  28.                 {
  29.                     n=n/2;
  30.                 }
  31.                 else if(n%2==1)
  32.                 {
  33.                     n=n*3+1;
  34.                 }
  35.                 count++;
  36.             }
  37.  
  38.             if(count>max)
  39.             {
  40.                 max=count;
  41.             }
  42.             count=1;
  43.  
  44.         }
  45.  
  46.         cout<<max<<endl;
  47.     }
  48.  
  49.     return 0;
  50. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement