-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathp14.cpp
35 lines (34 loc) · 799 Bytes
/
p14.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
#include <iostream>
int main()
{
std::cout << "Here we go...." << std::endl;
long foo[1000000] = {};
long max = 1;
long maxProd = 1;
for (long i = 1; i <= 1000000; i++)
{
long n = i;
if (foo[i] != 0)
continue;
long j = 1;
while (n != 1)
{
n = n % 2 == 0 ? n / 2 : 3 * n + 1;
if (n > 0 && n <= 1000000 && foo[n] != 1)
{
j += foo[(long)n];
n = 1;
}
else
{
j++;
}
}
foo[i] = j;
max = j > max ? j : max;
maxProd = j == max ? i : maxProd;
}
std::cout << "max...." << max << std::endl;
std::cout << "maxProd.. " << maxProd << std::endl;
return 0;
}