您的位置:首页 > 理论基础 > 计算机网络

https://projecteuler.net/problem=10

2016-02-25 14:36 453 查看

Summation of primes

Problem 10

The sum of the primes below 10 is 2 + 3 + 5 + 7 = 17.

Find the sum of all the primes below two million.

此题就是考察素筛法,如果一个一个算,没太大必要

primelist = [True] * 2000001
for i in range(2,2000001):
if primelist[i] == True:
temp = i * 2
while temp < 2000001:
primelist[temp] = False
temp += i
result = 0
for i in range(2,2000001):
if primelist[i] == True:
result += i
print(result)
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: