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.

Try Is Prime in Calcul.io

Start with one of the editable examples above, then replace its arguments with your own values. Keeping the function on a separate calculator line makes the input and result easy to compare. For a longer workflow, assign the result to a variable or reference that line in the next expression.

Check the shown signature before adding optional arguments, and use the related-function links to compare operations with similar purposes.

All functions