uva 371 - Ackermann Functions

 

 1 #include <cstdio>
 2 
 3 int main()
 4 {
 5     long int F, S, I, Count, Value, Max, J;
 6     while(scanf("%ld %ld", &F, &S) && F)
 7     {
 8         if(F > S) { F ^= S; S ^= F; F ^= S; }
 9         Max = 0;
10         for(I = F; I <= S; I++)
11         {
12             Count = 0;
13             J = I;
14             do{
15                 if(J % 2) (J *= 3) ++;
16                 else J /= 2;
17                 Count ++;
18             }while(J != 1);
19             if(Count > Max) { Value = I; Max = Count; }
20         }
21         printf("Between %ld and %ld, %ld generates the longest sequence of %ld values.\n",F, S, Value, Max);
22     }
23     return 0;
24 }

 

posted @ 2016-01-20 13:12  小小泽  阅读(179)  评论(0编辑  收藏  举报