为什么我的算法找到所有低于 200 万的素数之和的算法这么慢?我是一个相当初学者的程序员,这就是我找到解决方案的方法:
import time
sum = 2
start = time.time()
for number in range(3, 2000000):
prime = True
for x in range(2, number):
if number % x == 0:
prime = False
if prime:
sum += number
print "Sum =", sum
end = time.time() - start
print "Runtime =", end
有人可以帮我吗?谢谢!