Created
August 9, 2013 22:36
-
-
Save akkerman/6197876 to your computer and use it in GitHub Desktop.
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 | |
def is_prime(n): | |
if (n == 2): | |
return True | |
if (n == 1 or n % 2 == 0): | |
return False | |
square = int(math.ceil(math.sqrt(abs(n)))) + 1 | |
i = 3 | |
while i <= square: | |
if (n % i == 0): | |
return False | |
i+=2 | |
return True |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment