From a0c3ebee6f019a327d057b7861ef6070333e276f Mon Sep 17 00:00:00 2001 From: daviddoji Date: Thu, 24 Jun 2021 20:37:35 +0200 Subject: [PATCH] Add function to check primality --- src/Python/utils.py | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/src/Python/utils.py b/src/Python/utils.py index 2188079..62a3602 100644 --- a/src/Python/utils.py +++ b/src/Python/utils.py @@ -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 \ No newline at end of file