isPrime

isPrime(x)

Try it yourself:


isPrime(): test primality

isPrime(n) returns whether n is a prime number: an integer greater than 1 with exactly two positive divisors, 1 and itself. Thus 2, 3, and 5 are prime; 1 and 4 are not.

Why primes matter

Primes are building blocks of integers and are important in factorization, hashing, and public-key cryptography. Use gcd() to examine shared factors, invmod() in modular arithmetic, and mod() to inspect remainders.

Input rules

Supply a finite integer. A negative number, zero, one, or fraction is not prime. Validate with isInteger() and isFinite() when input is external.

All functions