Skip to content

Instantly share code, notes, and snippets.

@TheRealMentor
Created June 28, 2019 16:20
Show Gist options
  • Save TheRealMentor/8374c3666c0100144d8b164b8727251d to your computer and use it in GitHub Desktop.
Save TheRealMentor/8374c3666c0100144d8b164b8727251d to your computer and use it in GitHub Desktop.
'''
@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