Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- 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
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement