-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path050.py
28 lines (22 loc) · 793 Bytes
/
050.py
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
'''
The prime 41, can be written as the sum of six consecutive primes:
41 = 2 + 3 + 5 + 7 + 11 + 13
This is the longest sum of consecutive primes that adds to a prime below one-hundred.
The longest sum of consecutive primes below one-thousand that adds to a prime, contains 21 terms, and is equal to 953.
Which prime, below one-million, can be written as the sum of the most consecutive primes?
'''
import prime
MAX = 5000
prime.prime(MAX)
def check_length(n, below):
maxprime = 0
for x in xrange(0, below):
total = sum(prime.prime_list[x:x+n])
if total > below: break
if prime.isprime(total): maxprime = total
return maxprime
for n in xrange(1000, 0, -1):
maxprime = check_length(n, 1000000)
if maxprime:
print maxprime
break