Edited problems 35, 37 to use long version of primes.c.
This commit is contained in:
parent
509cb46f37
commit
5bfa0b53a2
8
35.c
8
35.c
|
@ -7,14 +7,14 @@
|
||||||
int main () {
|
int main () {
|
||||||
int bound = 1000000;
|
int bound = 1000000;
|
||||||
|
|
||||||
int* primes;
|
long* primes;
|
||||||
bool* primesTable;
|
bool* primesTable;
|
||||||
int numPrimes = listOfPrimes (bound, &primes, &primesTable);
|
long numPrimes = listOfPrimes (bound, &primes, &primesTable);
|
||||||
|
|
||||||
bool* circularPrimesTable = calloc (bound + 1, sizeof (bool));
|
bool* circularPrimesTable = calloc (bound + 1, sizeof (bool));
|
||||||
for (int i = 0; i < numPrimes; i++) {
|
for (long i = 0; i < numPrimes; i++) {
|
||||||
if (circularPrimesTable[primes[i]] != true) {
|
if (circularPrimesTable[primes[i]] != true) {
|
||||||
int n = primes[i];
|
long n = primes[i];
|
||||||
int numOfDigits = floor (log10 (n)) + 1;
|
int numOfDigits = floor (log10 (n)) + 1;
|
||||||
int* digits = malloc (sizeof (int) * numOfDigits);
|
int* digits = malloc (sizeof (int) * numOfDigits);
|
||||||
for (int d = 0; d < numOfDigits; d++) {
|
for (int d = 0; d < numOfDigits; d++) {
|
||||||
|
|
8
37.c
8
37.c
|
@ -25,13 +25,13 @@ bool isRightTrunc (int n) {
|
||||||
}
|
}
|
||||||
|
|
||||||
int main () {
|
int main () {
|
||||||
int* primes;
|
long* primes;
|
||||||
int numOfPrimes = listOfPrimes (1000000, &primes, &primesTable);
|
long numOfPrimes = listOfPrimes (1000000, &primes, &primesTable);
|
||||||
// unfortunately I couldn't find a deterministic way to find
|
// unfortunately I couldn't find a deterministic way to find
|
||||||
// the upper-bound of all truncatable primes... 1 mil will do
|
// the upper-bound of all truncatable primes... 1 mil will do
|
||||||
|
|
||||||
int sum = 0;
|
long sum = 0;
|
||||||
for (int i = 0; i < numOfPrimes; i++) {
|
for (long i = 0; i < numOfPrimes; i++) {
|
||||||
if (isLeftTrunc (primes[i]) &&
|
if (isLeftTrunc (primes[i]) &&
|
||||||
isRightTrunc (primes[i]) &&
|
isRightTrunc (primes[i]) &&
|
||||||
primes[i] > 10) {
|
primes[i] > 10) {
|
||||||
|
|
Loading…
Reference in New Issue