-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProblem45.cpp
More file actions
40 lines (36 loc) · 712 Bytes
/
Copy pathProblem45.cpp
File metadata and controls
40 lines (36 loc) · 712 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
/*
Krishna Mohan
Project Euler - Problem 45
Date: 3/24/2015
*/
#include <bits/stdc++.h>
using namespace std;
#define fo(i, n) for(int (i)=0;(i)<(n); (i)++)
#define MAX 100000001
typedef unsigned long long ull;
int main()
{
ios_base::sync_with_stdio(0);
/*
As all tri are hex, we need to check pent and hex only
*/
ull hv=0, pv=0, h=2, p=2, cnt=0;
while(true)
{
hv=h*((2*h)-1);
while(pv<hv)
{
pv=(p*((3*p)-1))/2;
p++;
}
if(pv==hv)
{
cout<<pv<<" -> "<<(p-1)<<" : "<<h<<endl;
cnt++;
}
if(cnt==2)
break;
h++;
}
return 0;
}