Created
September 30, 2019 15:34
-
-
Save codecakes/6941f8197ba424a95f91c3705385dc98 to your computer and use it in GitHub Desktop.
is Prime
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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