Advertisement
royalsflush

UVa 100 AC

Mar 22nd, 2013
106
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.41 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <algorithm>
  3. using namespace std;
  4.  
  5. int a,b;
  6. int l,h,best;
  7.  
  8. int count(int x) {
  9.     int c=1;
  10.    
  11.     while (x!=1) {
  12.         if (x&1) x=3*x+1;
  13.         else x/=2;
  14.         c++;
  15.     }
  16.  
  17.     return c;
  18. }
  19.  
  20. int main() {
  21.     while(scanf("%d %d", &a,&b)!=EOF) {
  22.         l=a, h=b,best=-1;
  23.         if (l>h) swap(l,h);
  24.    
  25.         for (int i=l; i<=h; i++)
  26.             best=max(best,count(i));
  27.  
  28.         printf("%d %d %d\n", a,b,best);
  29.     }
  30.    
  31.     return 0;
  32. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement