-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpy.py
45 lines (37 loc) · 906 Bytes
/
py.py
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
def isprime(n):
""" Python program to check whether a number is prime or not """
if n == 2:
return True
if n == 3:
return True
if n % 2 == 0:
return False
if n % 3 == 0:
return False
i = 5
w = 2
while i * i <= n:
if n % i == 0:
return False
i += w
w = 6 - w
return True
def slowIsPrime(n):
"""Slow, But would work around almost all test cases """
if n<0:
return False
elif n==1:
False
else:
flag = 0
if n%2 == 0 and n!=2:
flag = 1
else:
for i in range(3, int(n**(1/2))+1, 2):
if n%i ==0:
flag = 1
break
if flag == 0:
True
else:
False