Last active
August 29, 2015 14:18
-
-
Save ficapy/2ea0ca37317f55577ec6 to your computer and use it in GitHub Desktop.
心酸T^T
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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