Last active
February 5, 2024 01:29
-
-
Save gregorydickson/d50ff5df0b24f28c7330567e7e7e23cf to your computer and use it in GitHub Desktop.
Python Sieve of Eratosthenes
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
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