Created
August 19, 2012 01:32
-
-
Save theonewolf/3390820 to your computer and use it in GitHub Desktop.
Sieve of Erastosthenes
This file contains hidden or 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
| def sieve_of_erastosthenes(till): | |
| primelist = [True]*(till+1) | |
| primelist[0] = primelist[1] = False | |
| nextprime = (i for i,v in enumerate(primelist) if v) | |
| while (True): | |
| try: | |
| prime = nextprime.next() | |
| except StopIteration: | |
| return primelist | |
| for i in xrange(prime*prime,till+1,prime): | |
| primelist[i] = False |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment