Add function to check primality

This commit is contained in:
David Doblas Jiménez 2021-06-24 20:37:35 +02:00
parent a062b67759
commit a0c3ebee6f

View File

@ -1,4 +1,4 @@
import math
from functools import wraps from functools import wraps
@ -14,3 +14,13 @@ def timeit(name):
return result return result
return wrapper return wrapper
return profile 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