Advertisement
Saleh127

UVA 371 / Memo

Nov 30th, 2021
705
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.25 KB | None | 0 0
  1. /***
  2.  created: 2021-11-30-22.00.28
  3. ***/
  4.  
  5. #include <bits/stdc++.h>
  6. using namespace std;
  7. #define ll long long
  8. #define test int tt; cin>>tt; for(int cs=1;cs<=tt;cs++)
  9. #define get_lost_idiot return 0
  10. #define nl '\n'
  11.  
  12. map<ll,ll>x;
  13.  
  14. int main()
  15. {
  16.    ios_base::sync_with_stdio(0);
  17.    cin.tie(0);cout.tie(0);
  18.  
  19.    ll n,m,i,j,k,l,r;
  20.  
  21.    while(cin>>l>>r && (l+r))
  22.    {
  23.         if(l>r) swap(l,r);
  24.  
  25.         k=0;
  26.         for(i=l;i<=r;i++)
  27.         {
  28.              if(x[i])
  29.              {
  30.                   if(x[i]>k)
  31.                   {
  32.                        k=x[i];
  33.                        m=i;
  34.                   }
  35.              }
  36.              else
  37.              {
  38.                   j=0;
  39.                   n=i;
  40.                   while(1)
  41.                   {
  42.                        if(n%2) n=3*n+1;
  43.                        else n/=2;
  44.                        j++;
  45.  
  46.                        if(n==1) break;
  47.                   }
  48.                   x[i]=j;
  49.                   if(x[i]>k)
  50.                   {
  51.                        k=x[i];
  52.                        m=i;
  53.                   }
  54.              }
  55.         }
  56.         cout<<"Between "<<l<<" and "<<r<<", "<<m<<" generates the longest sequence of "<<k<<" values."<<nl;
  57.    }
  58.  
  59.  
  60.  
  61.    get_lost_idiot;
  62. }
  63.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement