-
Notifications
You must be signed in to change notification settings - Fork 0
/
id0050.c
61 lines (46 loc) · 1.14 KB
/
id0050.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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
// Licensed under the MIT License.
// Consecutive Prime Sum
#include "../lib/euler.h"
#include "../lib/sieve.h"
int main(void)
{
long maxSum = 0;
long maxLength = 0;
struct Sieve primes;
clock_t start = clock();
euler_ok(sieve(&primes, 1000000l));
long long* begin = primes.primes.items;
long long* end = begin + primes.primes.count;
for (long long* p = begin; p < end; p++)
{
long sum = 0;
for (long long* q = p; q < end; q++)
{
sum += *q;
if (sum > 1000000l)
{
break;
}
if (sum <= maxSum)
{
continue;
}
long length = q - p;
if (length <= maxLength)
{
continue;
}
Primality test = sieve_test(
&primes,
sum,
miller_rabin_primality_test);
if (test != PRIMALITY_PRIME)
{
continue;
}
maxSum = sum;
maxLength = length;
}
}
return euler_submit(50, maxSum, start);
}