Sieve of Eratosthenes in Python


SUBMITTED BY: Guest

DATE: June 5, 2015, 8:44 a.m.

FORMAT: Python

SIZE: 186 Bytes

HITS: 2099

  1. def eratosthenes2(n):
  2. multiples = set()
  3. for i in range(2, n+1):
  4. if i not in multiples:
  5. yield i
  6. multiples.update(range(i*i, n+1, i))

comments powered by Disqus