From 4038f3d0299723023ee514ffb9646c36c6f9e16b Mon Sep 17 00:00:00 2001 From: NatanLucena <44265910+NatanLucena@users.noreply.github.com> Date: Tue, 22 Oct 2019 17:04:54 -0300 Subject: [PATCH] Create isPrime.py --- allalgorithms/numeric/isPrime.py | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) create mode 100644 allalgorithms/numeric/isPrime.py diff --git a/allalgorithms/numeric/isPrime.py b/allalgorithms/numeric/isPrime.py new file mode 100644 index 0000000..be69e9c --- /dev/null +++ b/allalgorithms/numeric/isPrime.py @@ -0,0 +1,26 @@ +# -*- coding: UTF-8 -*- +# +# Check if is prime +# The All â–²lgorithms library for python +# +# Contributed by: Natan Lucena +# Github: @NatanLucena +# + +def isPrime(n) : + + if (n <= 1) : + return False + if (n <= 3) : + return True + + if (n % 2 == 0 or n % 3 == 0) : + return False + + i = 5 + while(i * i <= n) : + if (n % i == 0 or n % (i + 2) == 0) : + return False + i = i + 6 + + return True