Skip to content

Instantly share code, notes, and snippets.

@ficapy ficapy/primers.py
Last active Aug 29, 2015

Embed
What would you like to do?
心酸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
You can’t perform that action at this time.