Skip to content

Instantly share code, notes, and snippets.

@codecakes
Created September 30, 2019 15:34
Show Gist options
  • Select an option

  • Save codecakes/6941f8197ba424a95f91c3705385dc98 to your computer and use it in GitHub Desktop.

Select an option

Save codecakes/6941f8197ba424a95f91c3705385dc98 to your computer and use it in GitHub Desktop.
is Prime
def isPrime(n):
if n < 2: return False
if n >2 and not n%2:
return False
limit = n + 1
primes = set()
not_primes = set()
for num in range(3, limit):
# if odd and not in primes yet
if num % 2 and num not in not_primes:
for p in range(num * 2, limit, num):
not_primes.add(p)
if p == n:
return False
return True
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment