-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy path100.cpp
49 lines (40 loc) · 860 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
#include <iostream>
#include <cstdint>
using namespace std;
int64_t counter(int64_t input);
int64_t maxBetween(int64_t num1, int64_t num2);
int main() {
int64_t input1 = 0;
int64_t input2 = 0;
while (cin >> input1 >> input2) {
if (input1 >= input2) {
cout << input1 << ' ' << input2 << ' ' << maxBetween(input2, input1) << endl;
} else {
cout << input1 << ' ' << input2 << ' ' << maxBetween(input1, input2) << endl;
}
}
return 0;
}
int64_t counter(int64_t input) {
int64_t count = 1;
while (input != 1) {
if (input % 2 == 1) {
input = (3 * input) + 1;
} else {
input = (input / 2);
}
count++;
}
return count;
}
int64_t maxBetween(int64_t num1, int64_t num2) {
int64_t max = 0;
int64_t temp = 0;
for (int64_t i = num1; i <= num2; i++) {
temp = counter(i);
if (temp > max) {
max = temp;
}
}
return max;
}