Skip to content

Instantly share code, notes, and snippets.

@ssanin82
Created December 16, 2017 03:09
Show Gist options
  • Save ssanin82/ee78bef0dc2f649ab40360e562a26d19 to your computer and use it in GitHub Desktop.
Save ssanin82/ee78bef0dc2f649ab40360e562a26d19 to your computer and use it in GitHub Desktop.
def get_primes_to(n):
D, q = {}, 2
while q <= n:
if q not in D:
yield q
D[q * q] = [q]
else:
for p in D[q]:
D.setdefault(p + q, []).append(p)
del D[q]
q += 1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment