fork(1) download
  1. def ifrom(n):
  2. while True:
  3. yield n
  4. n += 1
  5.  
  6. def sieve(n, xs):
  7. for i in xs:
  8. if i % n != 0:
  9. yield i
  10.  
  11. def primes():
  12. xs = ifrom(2)
  13. while True:
  14. n = next(xs)
  15. yield n
  16. xs = sieve(n, xs)
  17.  
  18. if __name__ == '__main__':
  19. for i, p in zip(range(20), primes()):
  20. print(p, end=' ')
  21.  
Success #stdin #stdout 0.03s 9156KB
stdin
Standard input is empty
stdout
2 3 5 7 11 13 17 19 23 29 31 37 41 43 47 53 59 61 67 71