Last active
January 30, 2023 02:32
-
-
Save curegit/ec9a4b0ec3d280aa5bcb2d79cd8485e2 to your computer and use it in GitHub Desktop.
エラトステネスの篩で素数を無限に列挙する
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 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