sieve-v1.py 409 B

123456789101112131415161718
  1. from math import ceil
  2. def f(n=1000000):
  3. roundUp = lambda n, prime: int(ceil(float(n) / prime))
  4. arr = [True] * n
  5. arr[0] = False
  6. arr[1] = False
  7. primeList = []
  8. for curr in range(2, n):
  9. if not arr[curr]:
  10. continue
  11. primeList.append(curr)
  12. for multiplicant in range(2, roundUp(n, curr)):
  13. arr[multiplicant * curr] = False
  14. return primeList