-
Notifications
You must be signed in to change notification settings - Fork 0
/
Problem 14.cpp
48 lines (41 loc) · 1.01 KB
/
Problem 14.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
#include<iostream.h>
//#define DEBUG
long long sequence(long long num);
long long currentIterations = 0;
long long maxIterations = 0;
long long largestNum = 0;
const long long range = 1000000;
int main(){
//cout << sequence(1000000) << " " << currentIterations << endl;
//system("PAUSE");
for(long long i = 1; i < range; i++){
sequence(i);
#ifdef DEBUG
cout << currentIterations << " " << i << endl;
system("PAUSE");
#endif
if (currentIterations > maxIterations){
maxIterations = currentIterations;
largestNum = i;
}
currentIterations = 0;
}
cout << maxIterations << " " << largestNum << endl;
system("PAUSE");
}
long long sequence(long long num){
#ifdef DEBUG
cout << num << endl;
system("PAUSE");
#endif
if (num == 1){
currentIterations++;
return 1;
} else if (num % 2 == 0){
currentIterations++;
return (sequence(num/2));
} else {
currentIterations++;
return (sequence((3 * num) + 1));
}
}