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)
1万+

被折叠的 条评论
为什么被折叠?



