Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
oorrja
GitHub Repository: oorrja/learntosolveit
Path: blob/master/languages/python/algorithm_eratosthenes.py
1240 views
1
def eratosthenes():
2
D = {}
3
q = 2
4
while True:
5
p = D.pop(q, None)
6
if p:
7
x = p + q
8
while x in D:
9
x += p
10
D[x] = p
11
else:
12
D[q*q] = q
13
yield q
14
q += 1
15
16
17