Advertisement
Rehan_Rahman26

UVA 100 __ The 3n+1

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