Skip to content

Instantly share code, notes, and snippets.

@iizukak
Created July 16, 2012 14:04
Show Gist options
  • Select an option

  • Save iizukak/3122897 to your computer and use it in GitHub Desktop.

Select an option

Save iizukak/3122897 to your computer and use it in GitHub Desktop.
project euler problem 10
#project euler problem 10
#auther @iizukak
#Sieve of Eratosthenes
#Find primes under n
def sieve(n):
primes = []
table = [0 for i in range(n+1)]
for i in range(2, n+1):
if table[i] == 0:
primes.append(i)
j = 2
while(i * j <= n):
table[i * j] = table[i * j] + 1
j = j + 1
return primes
print(sum(sieve(2000000)))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment