Problem Type : Ad Hoc
#include<stdio.h>
unsigned long long react(long long n,long long m , long long count)
{
if(n==1)
{
count++;
return count;
}
else if(n%2==0)
{
n=n/2;
count++;
if(n>m)
return count;
return react(n,m,count);
}
else if(n%2==1)
{
n=(3*n +1);
count++;
if(n>m)
return count;
return react(n,m,count);
}
}
int main()
{
long long n,m,j,p,count,l,s,i=0;
while(scanf("%lld %lld",&n,&m)==2)
{
i++;
s=n;
l=0;
if(n<0 && m<0)
break;
else if(n<=m)
count = react(n,m,l);
printf("Case %lld: A = %lld, limit = %lld, number of terms = %lld\n",i,n,m,count);
}
return 0;
}
#include<stdio.h>
unsigned long long react(long long n,long long m , long long count)
{
if(n==1)
{
count++;
return count;
}
else if(n%2==0)
{
n=n/2;
count++;
if(n>m)
return count;
return react(n,m,count);
}
else if(n%2==1)
{
n=(3*n +1);
count++;
if(n>m)
return count;
return react(n,m,count);
}
}
int main()
{
long long n,m,j,p,count,l,s,i=0;
while(scanf("%lld %lld",&n,&m)==2)
{
i++;
s=n;
l=0;
if(n<0 && m<0)
break;
else if(n<=m)
count = react(n,m,l);
printf("Case %lld: A = %lld, limit = %lld, number of terms = %lld\n",i,n,m,count);
}
return 0;
}
No comments:
Post a Comment