Project Euler Problem 10-Summation of primes

还是素数线性筛

MAXN = 2000000
prime = [0 for i in range(MAXN+1)]


res = 0
for i in range(2,MAXN+1):
    if prime[i] == 0:
        res += i
        prime[0] += 1
        prime[prime[0]] = i
    j = 1
    while j <= prime[0] and prime[j]<=MAXN/i:
        prime[prime[j]*i] = 1
        if i%prime[j] == 0:
            break
        j += 1

print res
posted @ 2017-09-21 23:38  追梦的蚂蚁  阅读(131)  评论(0编辑  收藏  举报