Last active
October 26, 2021 23:50
-
-
Save tos-kamiya/a3bed7c9c44ed0afefd97843171f5373 to your computer and use it in GitHub Desktop.
Sieve of Eratosthenes in Python
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 simple_sieve(limit): | |
is_prime = [True] * (limit + 1) | |
for n in range(2, limit + 1): | |
if is_prime[n]: | |
for m in range(n * n, limit + 1, n): | |
is_prime[m] = False | |
return [n for n in range(2, limit + 1) if is_prime[n]] | |
def main(): | |
primes = simple_sieve(100) | |
print(primes) | |
if __name__ == '__main__': | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment