-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathid0058.c
41 lines (32 loc) · 844 Bytes
/
id0058.c
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
28
29
30
31
32
33
34
35
36
37
38
39
40
41
// Licensed under the MIT License.
// Spiral Primes
#include "../lib/euler.h"
#include "../lib/primality_test.h"
int main(void)
{
long count = 0;
int length = 1;
clock_t start = clock();
do
{
length += 2;
long loRight = length * length;
long loLeft = loRight - length + 1;
long hiLeft = loLeft - length + 1;
long hiRight = hiLeft - length + 1;
if (miller_rabin_primality_test(loLeft) == PRIMALITY_PRIME)
{
count++;
}
if (miller_rabin_primality_test(hiLeft) == PRIMALITY_PRIME)
{
count++;
}
if (miller_rabin_primality_test(hiRight) == PRIMALITY_PRIME)
{
count++;
}
}
while ((double)count / length >= 0.1 * 2);
return euler_submit(58, length, start);
}