Problem 45
This commit is contained in:
parent
36c2236e3f
commit
8ffef23d48
|
@ -0,0 +1,22 @@
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <math.h>
|
||||||
|
#include <stdbool.h>
|
||||||
|
|
||||||
|
bool isPentagonal (long long n) {
|
||||||
|
long long radicand = 24*n + 1;
|
||||||
|
long long sqrtr = sqrt (radicand);
|
||||||
|
return sqrtr * sqrtr == radicand && (sqrtr + 1) % 6 == 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
int main () {
|
||||||
|
long long n = 144LL;
|
||||||
|
while (true) {
|
||||||
|
long long hex = n * (2*n - 1);
|
||||||
|
if (isPentagonal (hex)) {
|
||||||
|
printf ("%lli\n", hex);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
n++;
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue