1. input n 2. print n 3. if n = 1 then STOP 4. if n is odd then n <-- 3n+1 5. else n <-- n/2 6. GOTO 2
Given the input 22, the following sequence of numbers will be
printed 22 11 34 17 52 26 13 40 20 10 5 16 8 4 2 1
1 10 100 200 201 210 900 1000
1 10 20 100 200 125 201 210 89 900 1000 174
#include<stdio.h>
int a[10010];
int main()
{
int i,j,t,k,max;
for(i=2;i<10010;i++)
{
t=i;
while(t!=1)
{
if(t%2==1)
t=t*3+1;
else
t/=2;
a[i]++;
}
}
while(scanf("%d%d",&j,&k)!=EOF)
{
max=0;
for(i=j;i<=k;i++)
{
if(max<a[i])
max=a[i];
}
printf("%d %d %d\n",j,k,max+1);
}
return 0;
}The 3n + 1 problem(南阳oj271)(打表法)
原文:http://blog.csdn.net/hdd871532887/article/details/41394499