Refactor is_prime function

This commit is contained in:
David Doblas Jiménez 2021-09-06 09:31:28 +02:00
parent c4a8283576
commit 4985501d1a

View File

@ -17,9 +17,9 @@ def timeit(name):
def is_prime(n):
if n % 2 == 0 and n > 2:
if n <2:
return False
for i in range(3, int(math.sqrt(n)) + 1, 2):
for i in range(2, int(math.sqrt(n)) + 1):
if n % i == 0:
return False
return True