Ackermann Functions |
#include<string.h>
int main()
{
long long l,u;
while(scanf("%lld %lld",&l,&u)==2)
{
if(l==0&&u==0)
break;
long long count=0,i,j,k,m,n,max=0;
if(u<l)
{
i=l;
l=u;
u=i;
}
for(i=l;i<=u;i++)
{
m=i;count=0;
while(m!=0)
{
count++;
if(m%2==0)
{
m=m/2;
}
else
{
m=3*m+1;
}
if(m==1)
break;
}
if(count>max)
{
max=count;
n=i;
}
}
printf("Between %lld and %lld, %lld generates the longest sequence of %lld values.\n",l,u,n,max);
}
return 0;
}
No comments:
Post a Comment