好久沒寫ACM,練練手感。
我也放上Github了,好久沒寫這麼多註解了,如果有問題可以問我。
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 <iostream>
*/
using namespace std;
long algorithm(long n){
long cycle = 1;
while(n > 1){
if(n%2 != 0){
n = 3*n + 1;
}else{
n = n/2;
}
cycle++;
}
return cycle;
}
int main(){
long i,j,n;
while(true){
cin >> i >> j ;
if(i>j){
long tmp = i;
i = j;
j = tmp;
}
long maxCycle = 0;
for(long n = i;n <= j;n++){
long nCycle = algorithm(n);
if(nCycle > maxCycle){
maxCycle = nCycle;
}
}
cout << i << " " << j << " "<< maxCycle <<endl;
}
return 0;
}
|