Project Euler Problem 7-10001st prime

素数线性筛

MAXN = 110100
prime = [0 for i in range(210000)]

for i in range(2,MAXN):
    if prime[i] == 0:
        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 prime[10001]
posted @ 2017-09-20 22:00  追梦的蚂蚁  阅读(160)  评论(0编辑  收藏  举报