forked from nayuki/Project-Euler-solutions
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathp050.py
More file actions
34 lines (29 loc) · 720 Bytes
/
p050.py
File metadata and controls
34 lines (29 loc) · 720 Bytes
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
#
# Solution to Project Euler problem 50
# Copyright (c) Project Nayuki. All rights reserved.
#
# https://www.nayuki.io/page/project-euler-solutions
# https://github.com/nayuki/Project-Euler-solutions
#
import eulerlib, sys
if sys.version_info.major == 2:
range = xrange
def compute():
ans = 0
isprime = eulerlib.list_primality(999999)
primes = eulerlib.list_primes(999999)
consecutive = 0
for i in range(len(primes)):
sum = primes[i]
consec = 1
for j in range(i + 1, len(primes)):
sum += primes[j]
consec += 1
if sum >= len(isprime):
break
if isprime[sum] and consec > consecutive:
ans = sum
consecutive = consec
return str(ans)
if __name__ == "__main__":
print(compute())