-
Notifications
You must be signed in to change notification settings - Fork 0
/
100.cpp
57 lines (43 loc) · 1021 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
56
57
/**
* AC - 0.037 secs
* Further optimizations after simple cache -
* Replaced division / multiplication with bit operators
* No improvements in speed :-(
*/
#include <iostream>
#include <stdio.h>
int Table[1000000] = {0};
int getCycleLen(int k) {
int len = 1;
while (k > 1) {
if (k & 0x0001) {
k = (k + k + k) + 1;
} else {
k = k >> 1;
}
len++;
}
return len;
}
int main() {
#ifndef ONLINE_JUDGE
freopen("100.in", "r", stdin);
#endif
int i, j, maxCycleLen;
while (std::cin >> i >> j) {
int orig_i = i;
int orig_j = j;
if (i > j) {
std::swap(i, j);
}
maxCycleLen = 0;
for (int k = i; k <= j; k++) {
if (Table[k] == 0) {
Table[k] = getCycleLen(k);
}
maxCycleLen = std::max(Table[k], maxCycleLen);
}
std::cout << orig_i << " " << orig_j << " " << maxCycleLen << std::endl;
}
return 0;
}