-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathuva100.cpp
More file actions
43 lines (32 loc) · 751 Bytes
/
Copy pathuva100.cpp
File metadata and controls
43 lines (32 loc) · 751 Bytes
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
/*
* Contest : UVA
* Problem : 100 - The 3n + 1 problem
* Link : https://vjudge.net/problem/UVA-100
*/
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define fastio ios::sync_with_stdio(0); cin.tie(0);
unordered_map<int, int> memo;
int f(int n) {
if (n == 1) return 1;
if (memo.count(n)) return memo[n];
int result;
if (n % 2 == 0) result = 1 + f(n / 2);
else
result = 1 + f(3 * n + 1);
return memo[n] = result;
}
void solve(int i, int j) {
int l = min(i, j),
r = max(i, j);
int maxLen = 0;
for (int k = l; k <= r; k++) maxLen = max(maxLen, f(k));
cout << i << " " << j << " " << maxLen << '\n';
}
int main() {
fastio
int i, j;
while (cin >> i >> j) solve(i, j);
return 0;
}