Skip to content

Instantly share code, notes, and snippets.

@mythnc
Created December 7, 2015 11:34
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mythnc/856782ce20d704f1ec69 to your computer and use it in GitHub Desktop.
Save mythnc/856782ce20d704f1ec69 to your computer and use it in GitHub Desktop.
judge n is prime or not
#!/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