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 >
 9 int  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

你可能感兴趣的:(em)