Created
May 3, 2012 17:53
-
-
Save dustinc/2587595 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
distance = 2000000 | |
primes = [1] * distance | |
def set_primes(): | |
primes[0] = 0 | |
primes[1] = 0 | |
for i in range(3, distance, 2): | |
if primes[i] == 1: | |
j = 2 | |
while i*j < len(primes): | |
if primes[i*j] == 1: | |
primes[i*j] = 0 | |
j += 1 | |
set_primes() | |
def is_prime(n): | |
return primes[n] == 1 | |
prime_sum = 2 | |
for i in range(3, distance, 2): | |
if is_prime(i): | |
prime_sum += i | |
print "sum of primes = %s" % (prime_sum) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment