1
0
Fork 0

Problem 46

This commit is contained in:
Jonathan Chan 2016-12-07 10:18:54 -08:00
parent 8ffef23d48
commit 8070bbffad
2 changed files with 37 additions and 0 deletions

BIN
46 Executable file

Binary file not shown.

37
46.c Normal file
View File

@ -0,0 +1,37 @@
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <stdbool.h>
#include "primes.h"
int main () {
long size = 10000;
long* primes;
bool* primesTable;
long numPrimes = listOfPrimes (size, &primes, &primesTable);
long n = 37;
while (n < size) {
if (!primesTable[n]) {
long p = 0;
bool decomposable = false;
while (n > primes[p]) {
long sq = (n - primes[p]) / 2;
long sqrtr = sqrt (sq);
if (sqrtr * sqrtr == sq) {
// printf ("%lli = %lli + 2 x %lli²\n", n, primes[p], sqrtr);
decomposable = true;
n += 2;
break;
}
else
p++;
}
if (!decomposable) {
printf ("%lli cannot be written as such.\n", n);
break;
}
}
else
n += 2;
}
}