Skip to content

Instantly share code, notes, and snippets.

@ficapy
Last active August 29, 2015 14:18
Show Gist options
  • Save ficapy/2ea0ca37317f55577ec6 to your computer and use it in GitHub Desktop.
Save ficapy/2ea0ca37317f55577ec6 to your computer and use it in GitHub Desktop.
心酸T^T
from functools import partial
import math
remove = lambda x, comp: not (x > comp and not x % comp)
def primerlist(n):
assert isinstance(n, int)
assert n >= 4
arr = range(2, n + 1)
flag = 2
end = int(math.sqrt(n))
while True:
if flag > end:
break
arr = list(filter(partial(remove, comp=flag), arr))
flag = next(i for i in arr if i > flag)
return arr
print(list(primerlist(200000)))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment