Discuss / Python / 另一个素数生成器

另一个素数生成器

Topic source

灰_手

#1 Created at ... [Delete] [Delete and Lock User]
def get_primes():
    yield 2
    found = [2]
    candidate = 3
    while True:
        if all(candidate % prime for prime in found):
            yield candidate
            found.append(candidate)
        candidate += 2

ps = get_primes()
for _, prime in zip(range(170), ps):
    print(prime, end=' ')

  • 1

Reply