-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path100.cpp
64 lines (54 loc) · 1.07 KB
/
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
56
57
58
59
60
61
62
63
64
#include <cstdio>
using namespace std;
int cnt[1000000];
int val(int x)
{
int tmpI, sum;
if (cnt[x] < 0) {
sum = 0;
tmpI = x;
while (tmpI > 1) {
if (tmpI % 2) {
sum += 2;
tmpI += (tmpI + 1) / 2;
}
else {
sum++;
tmpI /= 2;
}
if (tmpI < 1000000) {
sum += val(tmpI);
tmpI = 1;
}
}
cnt[x] = sum;
return sum;
}
else
return cnt[x];
}
int main(void)
{
int oL, oR, L, R, max, curr, i;
cnt[1] = 1;
cnt[2] = 2;
for (i = 3; i < 1000000; ++i)
cnt[i] = -1;
while (scanf("%d %d", &oL, &oR) != EOF) {
max = 0;
if (oL > oR) {
L = oR;
R = oL;
}
else {
L = oL;
R = oR;
}
for (i = L; i <= R; ++i) {
curr = val(i);
if (max < curr) max = curr;
}
printf("%d %d %d\n", oL, oR, max);
}
return 0;
}