Skip to content

Instantly share code, notes, and snippets.

@sota1235
Created April 14, 2014 06:45
Show Gist options
  • Select an option

  • Save sota1235/10622065 to your computer and use it in GitHub Desktop.

Select an option

Save sota1235/10622065 to your computer and use it in GitHub Desktop.
エラトステネスの篩 -暫定最強版-
def sieve(n):
num = [True]*n
num[0] = num[1] = False
for i in xrange(2,int(n**0.5)+1):
if num[i]:
for j in xrange(i**2, n, i):
num[j] = False
return [i for i in xrange(2,n) if num[i]]
print sieve(999999)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment