Last active
December 12, 2015 09:59
-
-
Save ashwch/4756288 to your computer and use it in GitHub Desktop.
Sieve of Eratosthenes
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
| """ | |
| Implementation of Sieve of Eratosthenes in python. | |
| Algorithm descripition : http://en.wikipedia.org/wiki/Sieve_of_Eratosthenes | |
| """ | |
| def primes(n): | |
| if n<=2: | |
| return [] | |
| sieve=[True]*(n+1) | |
| for x in range(3,int(n**0.5)+1,2): | |
| for y in range(3,(n//x)+1,2): | |
| sieve[(x*y)]=False | |
| return [2]+[i for i in range(3,n,2) if sieve[i]] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment