Consecutive prime sum
Problem 50
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?
from itertools import permutations
from tools import prime_set, is_prime
def run(limit=1000000):
primes = prime_set(limit)
for x in range(len(primes), 0, -1):
y = 0
num = sum(primes[y:x + y])
while num < limit:
end_prime = primes[-1]
if is_prime(num):
return num
y += 1
num = sum(primes[y:x + y])