UVA 694-The Collatz Sequence

奇怪啊一开始int一直TLE后来改成long就AC了 难道是uva环境的问题 求解。。。
#include<stdio.h>
int cnt=1;
long A,limit,tmp,ans;
int main()
{   while(~scanf("%ld%ld",&A,&limit)&&limit!=-1)
    {   ans=0;
        if(A==1)break;
        tmp=A;
        for(;;)
        {
            if(!(A&1))  {A/=2;ans++;}
            else    {A=3*A+1;ans++;}
            if(A>limit)break;
            if(A==1) {ans++;break;}
        }
        printf("Case %d: A = %ld, limit = %ld, number of terms = %ld\n",cnt,tmp,limit,ans);
        cnt++;
    }
   return 0;
}



你可能感兴趣的:(UVA 694-The Collatz Sequence)