Skip to content

Instantly share code, notes, and snippets.

@curegit
Last active January 30, 2023 02:32
Show Gist options
  • Save curegit/ec9a4b0ec3d280aa5bcb2d79cd8485e2 to your computer and use it in GitHub Desktop.
Save curegit/ec9a4b0ec3d280aa5bcb2d79cd8485e2 to your computer and use it in GitHub Desktop.
エラトステネスの篩で素数を無限に列挙する
from itertools import count
def prime():
def sieve(ints):
i = next(ints)
yield i
for n in sieve(k for k in ints if k % i != 0):
yield n
return sieve(count(2))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment