//C++ 5.3.0 - GNU C++ Compiler with options: -lm -lcrypt -O2 -pipe -DONLINE_JUDGE
#include<stdio.h>
#define MX 1000000
#define SWAP(X, Y) do { typeof(X) TMP = X; X = Y; Y = TMP; } while (0)
unsigned long DP[MX];
unsigned long tmp,max,k,t;
unsigned long cycleLen(unsigned long i,unsigned long n,unsigned long cnt)
{
if(i<MX && DP[i]){ DP[n]=cnt+DP[i];return DP[n]; }
if(i==1) { DP[n]=cnt;return DP[n]; }
if(i%2 == 0) return cycleLen(i/2,n,cnt+1);
return cycleLen(3*i+1,n,cnt+1);
}
unsigned long mxLen(unsigned long i,unsigned long j)
{
if(i>j) SWAP(i,j);
max=cycleLen(i,i,0)+1;
for(k=i+1;k<=j;k++){
t=cycleLen(k,k,0)+1;
if(max<t) max=t;
}
return max;
}
int main()
{
unsigned long i,j,mx;
//freopen("INPUT.TXT","r",stdin);
//freopen("OUTPUT.TXT","w",stdout);
while(scanf("%lu%lu",&i,&j)==2)
{
mx=mxLen(i,j);
printf("%lu %lu %lu\n",i,j,mx);
}
return 0;
}
No comments:
Post a Comment