Skip to content
Math & Statisticsnumber theory

Prime Number Checker

Whether a number is prime, and if not, its smallest factor. Trial division only up to the square root, which is all that is ever needed.

Also called: is this number prime, prime test.

Result
7919 is prime.

7919 is prime.

Smallest factor above 1
0
Prime (1 = yes)
1
Method and background

How this is calculated

If a number has a factor larger than its square root, it must also have one smaller, so testing beyond the square root finds nothing new. Skipping even numbers after two halves the work again.

test divisors up to sqrt(n)
d
A candidate divisor

Worked examples

Each of these is asserted on every build. If a change to the engine ever moved one of these answers, the build would fail before the page could print it.

7919 is the 1000th prime

Number
7,919

Result7919 is prime.

known value: 7919 is the 1000th prime

Open this example

2 is the only even prime

Number
2

Result2 is prime, the only even prime.

boundary

Open this example

1 is not prime

Number
1

Result1 is not prime. Primes are defined from 2 upward.

degenerate case: primes start at 2 by definition

Open this example