- Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathproblem045.cpp
More file actions
Latest commit
27 lines (24 loc) · 502 Bytes
/
Copy pathproblem045.cpp
File metadata and controls
27 lines (24 loc) · 502 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
#include<cmath>
#include<iostream>
boolisPentagonal(longlong n)
{
returnfmod(sqrt(24 * n + 1), 6) == 5;
}
intnextTriPentaHexagonal(int n)
{
int hexIndex = (sqrt(8 * n + 1) + 1) / 4;
int hex = hexIndex * (2 * hexIndex - 1);
int inc = 4 * hexIndex + 1;
for (;;) {
hex += inc;
if (isPentagonal(hex)) {
return hex;
}
inc += 4;
}
}
intmain()
{
std::cout << "Answer: " << nextTriPentaHexagonal(40755) << '\n';
return0;
}