1def 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