rev='made'/> name='keywords'/> name='author'/> ANURANAN: UVa Solution 100 : The 3n+1 problem

Welcome Note

Hi,
I'm Anisuzzaman Babla . I am a full stack Android Application Developer. I am working with Android for more than two years. I have completed my graduation from IIT, Jahangirnagar University. I have developed a series of commercially successful apps on Android. Moreover, 10+ of my Apps are live at Google play store. .
Thank You

UVa Solution 100 : The 3n+1 problem

#include<cstdio>
int cycle(long long int i) ;
int main()
{
    long long int a,b,c,x,y,i,max;
    while (scanf("%lld %lld",&a,&b)==2)
    {
        if (a<b){
            x=a;
            y=b;
        }
        else {
            x=b;
            y=a;
        }
        max=1;
        for (i=x;i<=y;i++)
        {
            c=cycle(i);
            if (c>max)
                max=c;
        }
        printf("%lld %lld %lld\n",a,b,max);
    }
}
int cycle(long long int i)
{
    int count=1;
    while (i>1)
    {
        if (i%2!=0)
            i=3*i+1;
        else
            i=i/2;
        count++;
    }
    return count;
}