MCPcopy Create free account
hub / github.com/codemistic/Data-Structures-and-Algorithms / is_prime

Function is_prime

Python/CP_Templates.py:55–70  ·  view source on GitHub ↗

Returns True if n is prime.

(n)

Source from the content-addressed store, hash-verified

53
54
55def is_prime(n):
56 """Returns True if n is prime."""
57 if n < 4:
58 return True
59 if n % 2 == 0:
60 return False
61 if n % 3 == 0:
62 return False
63 i = 5
64 w = 2
65 while i * i <= n:
66 if n % i == 0:
67 return False
68 i += w
69 w = 6 - w
70 return True
71
72# Sieve of Eratosthenes
73def sieve(n):

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected