Advertisement
shahan953

Untitled

Oct 16th, 2018
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.44 KB | None | 0 0
  1. #include<bits/stdc++.h>
  2. using namespace std;
  3.  
  4. //UVA Problem 100 (3n+1)
  5.  
  6. int main() {
  7.     long long n, i, j;
  8.     while(cin>>i>>j) {
  9.         long long mx=0;
  10.         for(int k=i;k<=j;k++){
  11.             long long  count = 0;
  12.             n = k;
  13.             while(1){
  14.                 count++;
  15.                 if(count>=mx) mx = count;
  16.                
  17.                 if(n==1) break;
  18.                 if(n%2 == 0) {
  19.                     n = n/2;
  20.                 } else {
  21.                     n = 3*n + 1;
  22.                 }
  23.             }
  24.         }
  25.        
  26.        
  27.         cout<<i<<" "<<j<<" "<<mx<<endl;
  28.        
  29.     }
  30.     return 0;
  31. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement