Add function to check primality

This commit is contained in:
daviddoji committed 2021-06-24 20:37:35 +02:00
1 parent a062b67759
commit a0c3ebee6f
1 file changed
+11 -1
+11 -1
View File
@@ -1,4 +1,4 @@
import math
from functools import wraps
@@ -14,3 +14,13 @@ def timeit(name):
return result
return wrapper
return profile
def is_prime(n):
if n % 2 == 0 and n > 2:
return False
for i in range(3, int(math.sqrt(n)) + 1, 2):
if n % i == 0:
return False
return True