2010-05-04 18:21:07 +00:00
|
|
|
"""Calculate the sum of all the primes below two million.
|
|
|
|
|
|
|
|
The sum of the primes below 10 is 2 + 3 + 5 + 7 = 17.
|
|
|
|
Find the sum of all the primes below two million.
|
|
|
|
"""
|
|
|
|
|
2010-09-10 14:21:43 +00:00
|
|
|
from e007 import prime_generator
|
2010-04-12 15:53:11 +00:00
|
|
|
|
2010-05-04 18:21:07 +00:00
|
|
|
def main():
|
|
|
|
print 'Fetching all primes for n < 2,000,000'
|
2010-09-10 14:21:43 +00:00
|
|
|
total = 0
|
|
|
|
generator = prime_generator()
|
|
|
|
while True:
|
|
|
|
prime = generator.next()
|
|
|
|
if prime >= 2000000:
|
|
|
|
break
|
|
|
|
total += prime
|
|
|
|
print 'Sum:', total
|
2010-05-04 18:21:07 +00:00
|
|
|
|
|
|
|
if __name__ == '__main__':
|
|
|
|
main()
|