MCPcopy Create free account
hub / github.com/Vishruth-S/CompetitiveCode / isPrime

Function isPrime

project_euler_problems/10001st prime/solution.py:14–29  ·  view source on GitHub ↗
(nb)

Source from the content-addressed store, hash-verified

12# - 1 is not a prime.
13# - All primes except 2 are odd.
14def isPrime(nb):
15 if nb == 1:
16 return False
17 elif nb == 2 or nb == 3:
18 return True
19 elif isEven(nb):
20 return False
21
22 # square root of `nb` rounded to the greatest integer `root` so that:
23 # root * root <= nb
24 root = math.ceil(math.sqrt(nb))
25
26 for f in range(3, root + 1, 2):
27 if nb % f == 0:
28 return False
29 return True
30
31
32# `count` starts to 1 because we already know that 2 is prime

Callers 1

solution.pyFile · 0.70

Calls 1

isEvenFunction · 0.70

Tested by

no test coverage detected