Created
March 22, 2021 15:03
-
-
Save saswata-dutta/db8960055eb6250e3733ed1e695bb5d3 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
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