杭电1032

/*********************************
* 日期:2011-2-18
* 作者:SJF
* 题号:杭电1032
* 题目:The 3n + 1 problem
* 结果:AC
**********************************/
#include <stdio.h>
unsigned CyCle(unsigned m)
{
unsigned count=1;
while(m!=1)
{
if(m%2==1)
{
m=3*m+1;
}
else
{
m/=2;
}
count++;
}
return count;
}

int main()
{
unsigned a,b,i;
while(scanf("%u%u",&a,&b)!=EOF)
{
unsigned max=0;
unsigned m1,m2;
if(a>b)
{
m2=a;
m1=b;
}
else
{
m1=a;
m2=b;
}
for(i=m1;i<=m2;i++)
{
if(max<CyCle(i))
{
max=CyCle(i);
}
}
printf("%u %u %u\n",a,b,max);
}
return 0;
}

你可能感兴趣的:(杭电)