Skip to main content

Primality Test

Definition​

The Primality Test Algorithm is a method used to determine whether a given integer is prime or not. It involves evaluating the divisibility of the number by smaller integers to ascertain if it has any factors other than 1 and itself. The algorithm leverages efficient techniques to minimize computational complexity

Practice​

isPrime(n):
if n < 2:
return false
if n == 2:
return true
if n % 2 == 0:
return false
limit = floor(sqrt(n))
for i = 3 to limit step 2:
if n % i == 0:
return false
return true