/home/toolbox/public_html/solutions/1/100/michael.c
1 /*@JUDGE_ID: 110101 100 C "3n+1"*/
2
3 #include <stdio.h>
4
5 unsigned long int func(unsigned long int num);
6 void swap(unsigned long int *tx,unsigned long int *ty);
7
8 int main(void)
9 {
10 unsigned long x,y,z,max=0,temp;
11 int flag;
12 fflush(stdout);
13 while (scanf("%lu %lu", &x,&y)==2)
14 {
15 flag = 0;
16 if (x>y)
17 {
18 swap(&x,&y);
19 flag =1;
20 }
21 max = 0;
22 for (z=x; z<=y; z++)
23 {
24 temp = func(z);
25 if (temp>max) max = temp;
26 }
27 if (!flag)
28 printf("%lu %lu %lu\n",x,y,max);
29 else
30 printf("%lu %lu %lu\n",y,x,max);
31 }
32 return 0;
33 }
34
35 void swap(unsigned long int *tx,unsigned long int *ty)
36 {
37 unsigned long int temp;
38 temp = *tx;
39 *tx = *ty;
40 *ty = temp;
41 }
42 unsigned long int func(unsigned long int num)
43 {
44 if (num == 1)
45 {
46 return 1;
47 }
48 else if (num%2==0)
49 {
50 return 1 + func(num/2);
51 }
52 else
53 {
54 return 1 + func(num*3+1);
55 }
56 }
57