UVa100

題目:
https://onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=3&page=show_problem&problem=36

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
#include <iostream>
#include <algorithm>

using namespace std;

int main(){
ios::sync_with_stdio(false);
cin.tie(nullptr);
cout.tie(nullptr);

int i, j;
int count, ans;
while(cin >> i >> j){
cout << i << ' ' << j << ' ';
count = ans = 0;
if(i > j) swap(i, j);
for(int a = i; a<=j; a++){
int num = a;
count = 0;
while(num > 1){
if(num % 2) num = num*3 + 1;
else num /= 2;
++count;
}
++count;
ans = max(count, ans);
}
cout << ans << '\n';
}
}