-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path14.cpp
98 lines (92 loc) · 1.52 KB
/
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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
#include<iostream>
#include<fstream>
#include<iomanip>
#include<math.h>
#include<cstdlib>
#include<sstream>
#include<vector>
#include <algorithm>
#include<numeric>
#include <iterator>
using namespace std;
int main()
{
long int bigNum = 1000000;
long int chainSize[bigNum];
chainSize[0] = 0;
chainSize[1] = 1;
for(long int i = 2; i < bigNum; i++)
{
long int seqSize = 1;
long int t = i;
do
{
if(t < i)
{
// cout << seqSize << endl;
seqSize = seqSize + chainSize[t] - 1;
// cout << i << "\t" << t << endl;
t = 1;
// cout << "break" << endl;
break;
}
else
{
if(t % 2 == 0) t = t/2;
else t = 3*t + 1;
seqSize++;
}
}while(t != 1);
// cout << i << "\t" << seqSize << endl;
chainSize[i] = seqSize;
}
// for (long int i = 0 ; i < bigNum; i++)
// {
// cout << i << "\t" << chainSize[i] << endl;
// }
int maxIndex = 0;
for(int i = 1; i < bigNum; i++)
{
if(chainSize[maxIndex] < chainSize[i])
{
maxIndex = i;
}
}
cout << maxIndex << endl;
return 0;
}
/*
long int n = 1000000, fof[n], max;
fof[0] = 0;
fof[1] = 1;
max = 1;
for (long int i = 2; i < n; i++)
{
long int chain = 1;
long int j = i;
do
{
if (j < i)
{
chain = chain + fof[j] - 1;
j = 1;
break;
}else{
if (j%2 == 0)
{
j = j/2;
}else{
j = 3*j + 1;
}
chain = chain + 1;
}
} while (j!=1);
fof[i] = chain;
if (fof[i] >= fof[max])
{
max = i;
cout << max << "\t" << fof[max] << endl;
}
// cout << fof[77031] <<endl;
}
*/