Created
June 28, 2019 16:20
-
-
Save TheRealMentor/8374c3666c0100144d8b164b8727251d 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
''' | |
@author: TheRealMentor | |
@date: 28/06/2019 | |
''' | |
import math | |
def sieve(A): | |
if A < 2: | |
return [] | |
allPrimes = [True] * (A+1) | |
allPrimes[0] = False | |
allPrimes[1] = False | |
for i in range(2, int(math.sqrt(A))+1): | |
if allPrimes[i]: | |
for j in range(i*2, A+1, i): | |
allPrimes[j] = False | |
return [i for i,b in enumerate(allPrimes) if b] | |
print(sieve(2)) | |
print(sieve(8)) | |
print(sieve(15)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment