MY name is ruhul amin

ISLAMIC UNIVERSITY OF KUSHTIA

Wednesday, March 13, 2013

uva solve problem 100 - The 3n + 1 problem

#include<stdio.h>
int main()
{
    long long int i,j,k,l,m,n,p,a,t;
    while(scanf("%lld%lld",&i,&j)==2)
    {
        if((i==0)&&(j==0))
        break;
        m=0;
        p=i;
        t=j;
        if(i>j)
        {
        k=p;
        p=t;
        t=k;
        }
        for(n=p;n<=t;n++)
        {
            l=n;
            a=1;
            while(l!=1)
            {
                if((l%2)==0)
                {
                l=l/2;
                a++;
                }
                else
                {
                l=3*l+1;
                a++;
                }

            }
            if(a>m)
            m=a;
        }
        printf("%lld %lld %lld\n",i,j,m);
    }
    return 0;
}

No comments:

Post a Comment