UVa 694 - The Collatz Sequence

#include<stdio.h>
int main()
{
    long long i,j,c=0,sum,temp,count;
    while(scanf("%lld %lld",&i,&j)==2 && i>0 && j>0)
    {
 
        count=1;
        temp=i;
        sum=0;
        while(temp!=1)
        {
            if(temp%2!=0)
                {
                    temp=3*temp+1;
                    sum+=temp;
                }
            else
                {
                    temp=temp/2;
                    sum+=temp;
                }
            if(temp>j)
                break;
            count++;
        }
 
        printf("Case %lld: A = %lld, limit = %lld, number of terms = %lld\n",++c,i,j,count);
    }
    return 0;
}
Share on Google Plus

About Unknown

This is a short description in the author block about the author. You edit it by entering text in the "Biographical Info" field in the user admin panel.
    Blogger Comment
    Facebook Comment

0 মন্তব্য(গুলি):

একটি মন্তব্য পোস্ট করুন