Created
August 19, 2015 00:43
-
-
Save zhangys-lucky/2ebc91615609184aae59 to your computer and use it in GitHub Desktop.
check prime
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
#! /usr/bin/python | |
from sys import argv | |
from math import sqrt | |
def is_prime(num): | |
s = sqrt(num) | |
step = 4 | |
if num <= 3: | |
return True | |
if num % 2 == 0 or num % 3 == 0: | |
return False | |
i = 5 | |
while i <= s: | |
if num % i == 0: | |
break | |
step ^= 6 | |
i += step | |
return i > s | |
a = int(argv[1]) | |
print(is_prime(a)) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment