HEU 6000 The 3n + 1 problem

 

 1/**************************************
 2Problem: HEU 6000 The 3n + 1 problem
 3Time: 0.0120 s
 4Memory: 236 k 
 5Accepted Time: 2009-04-02 13:54:11
 6Tips: 第一个数有可能比第二个大。 
 7**************************************/

 8#include <stdio.h>
 9int main()
10{
11    long a,b;
12    while(scanf("%ld%ld",&a,&b)!=EOF)
13    {
14        long i,j,max=0;
15        long aa=a<b?a:b;
16        long bb=a>b?a:b;
17        for(i=aa;i<=bb;i++)
18        {
19            long sum=1,temp=i;
20            while(temp!=1)
21            {
22                if(temp%2==1)temp=3*temp+1;
23                else temp/=2;
24                sum++;
25            }

26            if(sum>max)max=sum;
27        }

28        printf("%ld %ld %ld\n",a,b,max);
29    }

30    return 0;
31}

32
posted @ 2009-04-02 14:09  主函数  阅读(128)  评论(0编辑  收藏  举报