Skip to content

Instantly share code, notes, and snippets.

@dongho-jung
Created April 27, 2020 15:14
Show Gist options
  • Save dongho-jung/5583edba69599ec0853af75d47c116f5 to your computer and use it in GitHub Desktop.
Save dongho-jung/5583edba69599ec0853af75d47c116f5 to your computer and use it in GitHub Desktop.
get prime numbers. credit to https://codereview.stackexchange.com/a/121869
import itertools
def get_primes(n):
for i in itertools.chain([2], itertools.count(3, 2)):
if n <= 1: return
while n%i == 0:
n /= i
yield i
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment