-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathprime.py
More file actions
executable file
·47 lines (38 loc) · 842 Bytes
/
prime.py
File metadata and controls
executable file
·47 lines (38 loc) · 842 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
import re
import math
def myrange(start=0,n=0):
i = start
while i < n:
yield i
i += 1
def main():
str_num = raw_input("Enter a num : ")
if re.search(".+[024685]$",str_num):
#if re.search("(.+[024685]$)|(^1.*[02486]1$)",str_num):
print "not prime : ",str_num
return
num = long(str_num)
for i in myrange(2,long(num**0.5)+1L):
if num % i == 0:
print "not prime : ",num
print "divider : ",i
break
else:
print "prime num : ",num
def isprime(num):
if num == 2 or num == 1:
return True
if num % 2 == 0:
return False
for i in myrange(3,math.sqrt(num)+1L):
rem = num % i
if rem != 1 and isprime(rem):
return True
elif rem == 0:
return False
else:
return False
if __name__ == "__main__":
#main()
import sys
print isprime(long(sys.argv[1]))