Find the sum of all the primes below two million.
my code:
#!/usr/bin/env python
firstPrime = 5
topCandidate = 2000000
primeList = []
candidate = 5
inc = 2
while(candidate <= topCandidate):
position = 1
thisPrime = firstPrime
prime = 1
while(thisPrime * thisPrime <= candidate):
if(candidate % thisPrime == 0):
prime = 0
break
thisPrime = primeList[position]
position += 1
if(prime):
primeList.append(candidate)
candidate = candidate + inc
if(inc == 2):
inc = 4
else:
inc = 2
print sum(primeList) + 5
素数是真锻炼人阿..