-
Notifications
You must be signed in to change notification settings - Fork 68
/
100.cpp
55 lines (41 loc) · 766 Bytes
/
100.cpp
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
55
#include <iostream>
#include <stdlib.h>
using namespace std;
int main (void) {
int *tbl;
tbl = (int*)malloc(sizeof(int)*1000000);
memset (tbl, 0, 1000000);
tbl[1] = 1;
for (int i = 2; i < 1000000; i++) {
int temp = i;
int counter = 1;
while (temp > 1) {
if (temp < 1000000 && tbl[temp] > 0) {
counter += tbl[temp] - 1;
break;
}
counter++;
if (temp % 2 == 0)
temp /= 2;
else
temp = temp * 3 + 1;
}
tbl[i] = counter;
}
int a, b;
while (cin >> a >> b) {
cout << a << " " << b << " ";
if (a > b) {
b = b + a;
a = b - a;
b = b - a;
}
int max = 0;
for (int i = a; i <= b; i++) {
if (tbl[i] > max) max = tbl[i];
}
cout << max << endl;
}
free(tbl);
return 0;
}