-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProblem14.cpp
More file actions
52 lines (48 loc) · 1003 Bytes
/
Copy pathProblem14.cpp
File metadata and controls
52 lines (48 loc) · 1003 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
44
45
46
47
48
49
50
51
52
/*
Krishna Mohan
Project Euler - Problem 14
Date: 3/17/2015
*/
#include <bits/stdc++.h>
using namespace std;
#define fo(i, n) for(int (i)=0;(i)<(n); (i)++)
#define MAX 1000001
long long ans[MAX], maxv=0, maxi=0;
int main()
{
ios_base::sync_with_stdio(0);
fill(ans, ans+MAX, 1);
/*for(int i=1;i<14;i++)
cout<<i<<" -> "<<ans[i]<<endl;*/
for(int i=2;i<MAX;i++)
{
cout<<i<<endl;
long long num=i;
while(num!=1)
{
//cout<<num<<" -> ";
if(num&1)
num=3*num+1;
else
num/=2;
if(num<i)
{
ans[i]+=ans[num];
break;
}
else
{
ans[i]++;
}
}
if(ans[i]>maxv)
{
maxv=ans[i];
maxi=i;
}
}
for(int i=1;i<50;i++)
cout<<i<<" -> "<<ans[i]<<endl;
cout<<"max "<<maxi<<endl;
return 0;
}