-
Notifications
You must be signed in to change notification settings - Fork 0
/
14.c
54 lines (49 loc) · 957 Bytes
/
14.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
/*************************************************************************
> File Name: 14.c
> Author: qusijun
> Mail: [email protected]
> Created Time: 2014年05月19日 星期一 12时15分18秒
************************************************************************/
#include<stdio.h>
#define MAX 1000000
int generate(int n)
{
long long x = n;
int count = 0;
while(x != 1)
{
if(x%2)
{
x = 3*x +1 ;
}
else
{
x = x/2;
}
count++;
}
return count;
}
int max(int a,int b)
{
return (a>b)?a:b;
}
int main(void)
{
printf("%d,",generate(113383));
int len = 0;
int tmp = 0;
int tmp_i = -1;
for(int i = 2;i<MAX;i++)
{
tmp = generate(i);
printf("%d,%d\n",i,tmp);
if(len<tmp)
{
len = tmp;
tmp_i = i;
}
}
printf("%d,%d",tmp,tmp_i);
return 0;
}