Created
July 4, 2012 16:00
-
-
Save joehakimrahme/3048050 to your computer and use it in GitHub Desktop.
isprime - 6k +/- 1
This file contains 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
import math.sqrt as sqrt | |
def prime4(n): | |
if n<=1: | |
return False | |
if n % 2 == 0 and n != 2: | |
return False | |
if n % 3 == 0 and n != 3: | |
return False | |
# Limiting the tests to the 6k +/- 1 numbers | |
for i in (x for x in xrange(3, int(sqrt(n)), 2) | |
if x % 6 == 1 or x % 6 == 5): | |
if n % i == 0: | |
return False | |
return True |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment