求素数

def _not_divisible(n):
    return lambda x:x%n>0


def _odd_iter():
    n=1
    while True:
        n+=2
        yield n
def primes():
    yield 2
    it = _odd_iter()
    while True:
        n =next(it)
        yield n
        it = filter(_not_divisible(n),it)
        


for n in primes():
    if n <1000:
        print(n)
    else:
        break

posted @ 2019-08-22 16:14  ~李  阅读(103)  评论(0编辑  收藏  举报