Пример #1
0
from primes import is_prime_list

l = 1000000
is_prime = is_prime_list(l)
prime_list = [x for x in xrange(2, l) if is_prime[x]]

(n, m) = (0, 0)
for i in xrange(0, len(prime_list) - 1):
    
    prime_sum = 0
    for j in xrange(i, len(prime_list) - 1):
        prime_sum += prime_list[j]
        if prime_sum >= l:
            break
    
    for k in xrange(j, i, -1):
        prime_sum -= prime_list[k]
        if is_prime[prime_sum]:
            break
    
    d = k - i
    if d > n:
        (n, m) = (d, prime_sum)

print m
Пример #2
0
x = 3
m = 2
while x < 2000000:
    r = x ** 0.5
    for p in primes:
        if p > r:
            primes.append(x)
            m += x
            break
        if x % p == 0:
            break
    else:
        primes.append(x)
        m += x
    x += 2
print m

# or

l = 2000000
primes = is_prime_list(l)

m = 2
x = 3
while x < l:
    if primes[x]:
        m += x
    x += 2
print m