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

Welcome

Anisuzzaman Babla

Software Engineer at D Money Bangladesh Limited

I am an enthusiastic Android developer and interested in the newest technologies and trends. I have in total over five years of active Android development experience. I have worked on numerous projects used by hundreds of thousands of people. Moreover, 5+ of commercially successful apps are live at Google play store made by me.

I am eager to learn new things everyday. At the moment, my focus is on the new Java 8 and 9 language features, RxJava and RxAndroid, Kotlin, architectural patterns on Android (MVVM, MVP, etc.) and of course I am always up for trying out the newest Android libraries.

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;
}