Connect via MCP →

Enter Calculation

Enter a whole number greater than 1.

Formula

Advertisement

Results

Result for 2
prime
primality classification
Number 2
Factors Its only factors are 1 and 2
Previous prime No previous prime exists
Next prime 3

What is a prime number?

A prime number is a whole number greater than 1 that has exactly two positive divisors: 1 and itself. A composite number has more than two divisors. The number 1 is special: it has only one divisor, so it is neither prime nor composite. This calculator determines whether the number you enter is prime or composite, lists its factors, and shows the previous and next prime numbers.

Comparison of a prime number arranged as a single row of dots versus a composite number arranged as a rectangular grid of dots
A prime number cannot form a rectangle of dots, while a composite number can.

How to use it

Type a whole number greater than 1 into the field and submit. The tool classifies it as prime or composite, restates the number, lists all its factors (for composites), and reports the largest prime below it and the smallest prime above it.

The formula explained

We use deterministic trial division with the 6k±1 optimization. First we rule out 2 and 3 as known primes and reject even numbers and multiples of 3. Then we test only candidate divisors of the form \(6k-1\) and \(6k+1\) (5, 7, 11, 13, ...) up to the square root of \(n\). If none divides \(n\) evenly, \(n\) is prime. We only need to test up to the square root because any factor larger than the square root pairs with one smaller than it.

$$n = \text{Number} \text{ is prime} \iff n > 1 \;\wedge\; \nexists\, d \in [\,2,\ \lfloor\sqrt{n}\rfloor\,] : n \bmod d = 0$$

Advertisement
Diagram showing trial division checking divisors only up to the square root of n
Trial division only needs to test divisors from 2 up to the square root of n.

Worked example

Take \(n = 97\). Its square root is about \(9.85\). It is odd and not a multiple of 3. We test 5 (\(97 \bmod 5 = 2\)) and 7 (\(97 \bmod 7 = 6\)). The next candidate is 11, but \(11 \times 11 = 121 > 97\), so we stop. No divisor was found, so 97 is prime. The previous prime is 89 and the next prime is 101.

FAQ

Is 1 a prime number? No. 1 has only one divisor, so it is neither prime nor composite.

Is 2 prime? Yes. 2 is the smallest prime and the only even prime. It has no previous prime.

Why list factors only for composites? A prime by definition has only 1 and itself as factors, so the tool simply states that. Composites can have many factors, which are listed in ascending order.

Last updated: