<jupyter_start><jupyter_text>The prime 41, can be written as the sum of six consecutive primes:41 = 2 + 3 + 5 + 7 + 11 + 13This 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?<jupyter_code>N = 1000000

def FastPrimeSieve(max): # From http://rebrained.com/?p=458
    possible_primes = list(range(3, max + 1, 2))
    curr_index = -1
    max_index = len(possible_primes)
    for latest_prime in possible_primes:
        curr_index +=1
        if not latest_prime: 
            continue
        for index_variable_not_named_j in range((curr_index+latest_prime),max_index, latest_prime): 
            possible_primes[index_variable_not_named_j]=0
    possible_primes.insert(0,2)
    return list(filter(None, possible_primes))

P = FastPrimeSieve(N)
n = len(P)
S = [0]*(n+1)
for i in range(n):
    S[i+1] = S[i] + P[i]
P = set(P)
first = 0
last = 1
max_run = 0
best_prime = 0

while last < n:
    diff = S[last] - S[first]
    run = last - first
    if run > max_run and diff < N and diff in P:
        max_run = run
        best_prime = diff
    if diff < N:
        last += 1
    else:
        first += 1
        last = first + max_run

print(best_prime)<jupyter_output>997651
{'fraction_non_alphanumeric': 0.09419263456090651, 'fraction_numerical': 0.03541076487252125, 'mean_word_length': 3.037142857142857, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 1, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '1', 'dir': 'jupyter-structured-clean-dedup', 'id': '376622', 'license': 'MIT', 'n_tokens_mistral': 526, 'n_tokens_neox': 476, 'n_words': 159, 'path': 'Euler 050 - Consecutive prime sum.ipynb', 'repo_name': 'Radcliffe/project-euler', 'size': '1412'}