<jupyter_start><jupyter_text>- 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?**<jupyter_code>from tqdm import tqdm
import numpy as np
from sympy import sieve

N = 1e6
sieve._reset()
sieve.extend(N)

primes = np.array(sieve._list)
prime_set = set(primes)
cs = np.cumsum(primes)

primes.shape<jupyter_output><empty_output><jupyter_text>$f(i,n) = \sum_{i}^{i+n}P_i$$S = \texttt{primes} < 1000000$$\exists \ i^*, n^*: f(i^*, n^*) \in S \wedge \not \exists \ i', n' > n^*: \ f(i', n') \in S$<jupyter_code>d = -np.infty
p = None

for i in tqdm(range(len(primes))):
    for j in range(i, -1, -1):
        p_ = cs[i] - cs[j]
        if p_ > N: break
            
        if p_ in prime_set and (i - j) > d:
            d, p = i-j, p_
d, p<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.1407942238267148, 'fraction_numerical': 0.02527075812274368, 'mean_word_length': 3.2490421455938696, 'pattern_counts': {'":': 0, '<': 10, '<?xml version=': 0, '>': 12, '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': '2', 'dir': 'jupyter-structured-clean-dedup', 'id': '551986', 'license': 'MIT', 'n_tokens_mistral': 453, 'n_tokens_neox': 415, 'n_words': 146, 'path': 'src/p50.ipynb', 'repo_name': 'alexandru-dinu/project-euler', 'size': '1108'}