View Code
1 #include2 #include 3 __int64 p[1000005]; 4 void ff() 5 { 6 __int64 i,j,sum; 7 memset(p,-1,sizeof(p)); 8 p[1]=1; 9 p[2]=2;10 for(i=3;i<=1000000;i++)11 {12 j=i;13 sum=0;14 while(1){15 if(j%2 == 0)16 j/= 2;17 else j=j*3+1;18 sum++;19 // if(p[j]!=-1&&j<=1000000)20 if(j<=1000000&&p[j]!=-1)21 break;22 }23 p[i]=p[j]+sum;24 25 }26 }27 int main()28 {29 __int64 i,j,tpi,tpj,tp,sum,max,k;30 ff();31 while(scanf("%I64d%I64d",&i,&j)==2)32 {33 tpi=i;34 tpj=j;35 if(i>j)36 {37 tp=i;i=j;j=tp;38 }39 max=p[i];40 for(k=i;k<=j;k++)41 if(max<=p[k])42 max=p[k];43 printf("%I64d %I64d %I64d\n",tpi,tpj,max);44 }45 return 0;46 }