Skip to content

Instantly share code, notes, and snippets.

@saswata-dutta
Created March 22, 2021 15:03
Show Gist options
  • Save saswata-dutta/db8960055eb6250e3733ed1e695bb5d3 to your computer and use it in GitHub Desktop.
Save saswata-dutta/db8960055eb6250e3733ed1e695bb5d3 to your computer and use it in GitHub Desktop.
from math import isqrt
def primes_less_than(n: int) -> list[int]:
if n<= 2:
return []
is_prime = [True] * n
is_prime[0] = False
is_prime[1] = False
for i in range(2, isqrt(n)+1):
if is_prime[i]:
for x in range(i*i, n, i):
is_prime[x] = False
return [i for i in range(n) if is_prime[i]]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment