Skip to content

Instantly share code, notes, and snippets.

@tos-kamiya
Last active October 26, 2021 23:50
Show Gist options
  • Save tos-kamiya/a3bed7c9c44ed0afefd97843171f5373 to your computer and use it in GitHub Desktop.
Save tos-kamiya/a3bed7c9c44ed0afefd97843171f5373 to your computer and use it in GitHub Desktop.
Sieve of Eratosthenes in Python
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