programming-examples/python/Algorithms/primes.py

16 lines
299 B
Python
Raw Normal View History

2019-11-15 12:59:38 +01:00
def generate_primes(n):
sieve = [False, False] + [True] * (n - 1)
i = 2
while i * i <= n:
if sieve[i]:
sieve[2 * i::i] = [False] * (n // i - 1)
i += 1
return [i for i in range(len(sieve)) if sieve[i]]
def test():
print(generate_primes(10))
test()