-
-
Save nyango/fcb2651ddc893903d487176bd14bea3f to your computer and use it in GitHub Desktop.
Sieve of Eratosthenes by 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
import math | |
NUMBER = 100000000 | |
def get_prime_list(limit): | |
limit_sqrt = int(math.ceil(math.sqrt(limit))) | |
prime_bool_list = [False] * 2 + [True] * (limit - 2) | |
for prime_cand in xrange(2,limit_sqrt): | |
if prime_bool_list[prime_cand]: | |
for composite in range(prime_cand ** 2, limit, prime_cand): | |
prime_bool_list[composite] = False | |
return [i for i, b in enumerate(prime_bool_list) if b] | |
get_prime_list(NUMBER) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment