-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathproblem45.cpp
47 lines (42 loc) · 847 Bytes
/
problem45.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
#include <iostream>
#include <cmath>
using long_t = unsigned long long;
using namespace std;
long_t getTriangular(long_t i)
{
return i*(i+1)/2;
}
bool isflint(double x)
{
if (ceil(x) == x)
return true;
return false;
}
bool isPentagonal(double n)
{
double x1 = (1+sqrt(1+24*n))/6;
double x2 = (1+sqrt(1-24*n))/6;
if ( (x1 >= 0 && isflint(x1)) || (x2 >=0 && isflint(x2))){
return true;
}
return false;
}
bool isExagonal(double n)
{
double x1 = (1+sqrt(1+8*n))/4;
double x2 = (1+sqrt(1-8*n))/4;
if ( (x1 >= 0 && isflint(x1)) || (x2 >=0 && isflint(x2))){
return true;
}
return false;
}
int main()
{
long_t i = 286;
long_t x = getTriangular(i);
while (!isPentagonal(x) || !isExagonal(x)){
x = getTriangular(i);
i++;
}
cout<<x<<endl;
}