eratosthenes prime test exercise

This commit is contained in:
Xevion
2019-07-17 10:56:16 -05:00
parent 5b6af0eb12
commit 811357b6f8
4 changed files with 129 additions and 0 deletions
+7
View File
@@ -0,0 +1,7 @@
def primes(limit):
v = [False] * 2 + [True] * (limit+1)
for (i, prime) in enumerate(v):
if prime:
for x in range(i * i, limit+1, i):
v[x] = False
return [x for x, y in enumerate(v) if y and x <= limit]