1
0
Fork 0

Problem 45

This commit is contained in:
Jonathan Chan 2016-12-07 09:50:25 -08:00
parent 36c2236e3f
commit 8ffef23d48
2 changed files with 22 additions and 0 deletions

BIN
45 Executable file

Binary file not shown.

22
45.c Normal file
View File

@ -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++;
}
}