Created
December 7, 2015 11:34
-
-
Save mythnc/856782ce20d704f1ec69 to your computer and use it in GitHub Desktop.
judge n is prime or not
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/env python | |
# coding: utf-8 | |
import math | |
def prime(n): | |
if n <= 2: | |
return True | |
if n % 2 == 0: | |
return False | |
for i in range(3, int(math.sqrt(n)) + 1, 2): | |
if n % i == 0: | |
return False | |
return True | |
if __name__ == '__main__': | |
while True: | |
n = int(raw_input('enter n:\n')) | |
if n == 0: | |
break | |
if prime(n): | |
print 'prime\n' | |
else: | |
print 'not prime\n' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment