Problem 10
08 February 2002
The sum of the primes below 10 is 2 + 3 + 5 + 7 = 17.
Find the sum of all the primes below two million.
def fun10():
primes = [2]
result = 2
i = 3
while i < 2000000:
s = math.sqrt(i)
for p in primes:
if p > s:
primes.append(i)
result += i
break
else:
if i%p == 0:
break
i += 2
return result
answer is 142913828922, 一共用时12.3910000324,太长了
阅读(280) | 评论(0) | 转发(0) |