Last active
August 31, 2018 06:27
-
-
Save kupp1/ec2b3d47c4ce792dfa5ebb2728670670 to your computer and use it in GitHub Desktop.
Sieve of Eratosthenes
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
""" | |
Sieve of Eratosthenes | |
""" | |
import math | |
def erato_bool(n: int): | |
""" | |
Returned list of primary numbers form 2 to n-1 | |
""" | |
if n <= 2: | |
return [2, 3] | |
seq = [True] * n | |
edge = int(math.sqrt(n)) + 1 | |
for i in range(2, edge): | |
for j in range(i * 2, n, i): | |
seq[j] = False | |
return [i for i in range(n) if seq[i]][2:] | |
def erato_zero(n: int): | |
""" | |
Returned list of primary numbers form 2 to n-1 | |
""" | |
if n <= 2: | |
return [2, 3] | |
seq = list(range(n)) | |
edge = int(math.sqrt(n)) + 1 | |
for i in range(2, edge): | |
for j in range(i * 2, n, i): | |
seq[j] = 0 | |
return [i for i in seq if i][1:] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment