Skip to content

Instantly share code, notes, and snippets.

@gregorydickson
Last active February 5, 2024 01:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save gregorydickson/d50ff5df0b24f28c7330567e7e7e23cf to your computer and use it in GitHub Desktop.
Save gregorydickson/d50ff5df0b24f28c7330567e7e7e23cf to your computer and use it in GitHub Desktop.
Python Sieve of Eratosthenes
def count_primes(num):
list = [True for i in range(num+1)]
p = 2
while p*p <= num:
if list[p] == True:
for i in range(p*p, num+1, p):
list[i] = False
p += 1
return list.count(True) - 2
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment