Prime Number
checker.
Find out if a whole number is prime, see its factors, and find the primes next to it.
- Gap to previous prime
- 8
- Gap to next prime
- 4
- Digits
- 2
97 is prime. It sits 8 above the prime before it and 4 below the next.
Primes near your number
The block of 100 numbers from 1 holds 25 primes. 97 is one of them.
Working
- 1Only divisors up to √n matter√97 rounds down to 9, so test the primes up to 9
- 2Try each prime: none leaves 097 ÷ 2 leaves 1, ÷ 3 leaves 1, ÷ 5 leaves 2, ÷ 7 leaves 6
- 3Check: Fermat's little theorem holds296 leaves 1 when divided by 97, as it must for a prime
Primes from 1 to 100
| Prime | Gap | Twin with |
|---|---|---|
| 2 | First | None |
| 3 | 1 | 5 |
| 5 | 2 | 3 |
| 7 | 2 | 5 |
| 11 | 4 | 13 |
| 13 | 2 | 11 |
| 17 | 4 | 19 |
| 19 | 2 | 17 |
Check a list of numbers
Results
| Number | Result | Smallest factor |
|---|---|---|
| 91 | Composite | 7 |
| 97 | Prime | None |
| 561 | Composite | 3 |
| 1,001 | Composite | 7 |
| 65,537 | Prime | None |
| 1,000,000,007 | Prime | None |
Keyboard shortcuts
- Click the grid of 100 numbers or Tab to it, then press Right arrow for the next prime and Left arrow for the previous one.
- Up arrow and Down arrow in the number box add or take away 1, for numbers up to 15 digits.
- Hold Shift with the up or down arrow to move by 10.
- On the running count, the point moves with the arrow keys once it has focus.
How it's worked out
A prime is a whole number above 1 whose only divisors are 1 and itself. Every other number above 1 is composite: it splits into smaller factors. The number 1 is neither, since it has just one divisor.
Trial division tests the primes in order. You only need to go as far as the square root of the number. If n splits as a times b, the two parts cannot both be bigger than the root, because then their product would be bigger than n. So if no prime up to the root divides n, n is prime.
For 97 the root is a little under 10, so the primes to try are 2, 3, 5, 7. None of them leaves a remainder of 0, so 97 is prime. Up to one trillion the tool works this way, and the steps show each division or a count of the primes tried.
Above one trillion it uses the Miller–Rabin test. It writes n − 1 as a power of 2 times an odd number, then runs a fast power test for each of 13 bases, the primes from 2 to 41. A prime passes for every base. A composite almost always fails. The smallest odd composite that passes all 13 is 3,317,044,064,679,887,385,961,981, found by Sorenson and Webster. That has 25 digits, so for every number of up to 24 digits the test gives a proof, not a guess. For the largest 24-digit prime, n − 1 is 2 times the odd number 499,999,999,999,999,999,999,871.
The check at the end substitutes back. For a composite it multiplies the factor pair to get n again. For a prime it uses Fermat's little theorem: when p is prime and a is not a multiple of p, a to the power p − 1 leaves a remainder of 1 when divided by p.
Worked examples
Maya checks whether 91 is prime
A classmate tells Maya that 91 is prime. It is odd, it does not end in 5, and its digits add to 10, so the quick rules for 2, 3 and 5 all pass it. The root of 91 is between 9 and 10, so she only needs the primes up to 9.
Dividing 91 in turn: 2 leaves 1, 3 leaves 1, 5 leaves 1, 7 leaves 0. The remainder 0 means 7 goes in exactly, 13 times. So 91 is composite, and its factors are 7 × 13. The check multiplies them back: 7 times 13 is 91. The next prime after 91 is 97.
Dev checks a modulus before he uses it
Dev writes code that keeps its numbers small by taking remainders on division by 1,000,000,007. That only works the way he wants if the number is prime. Its root rounds down to 31,622, and there are 3,401 primes up to that point.
None of those 3,401 primes divides it, so it is prime, and the working ends with Fermat's check. It also shows how close the next primes are: 999,999,937 is 70 below, and 1,000,000,009 is just 2 above. Those two are twin primes, a pair two apart.
Mr. Okafor lists the primes from 1 to 100
For a class poster, Mr. Okafor lists every prime up to 100. The tool sieves the range: it crosses out the multiples of 2, 3, 5 and 7, the primes up to the root of 100, and what is left is 25 primes.
The table gives the gap before each prime. The widest gap is 8, from 89 to 97. There are 8 twin pairs: 3 and 5, 5 and 7, 11 and 13, 17 and 19, 29 and 31, 41 and 43, 59 and 61, 71 and 73. He can export the table as a file for the poster.
Reading your result
Composite answers show the factors in full up to one trillion. Above that, the tool shows the smallest prime factor if it is below one million. A number with two large prime factors is still proved composite, but finding those factors is a much harder job.
Gaps between primes grow slowly. Below 100 there are 25 primes, so one number in four is prime. Of the first million numbers, 78,498 are prime (OEIS A006880), which is fewer than one in twelve. The gap figures and the grid of 100 numbers show this thinning near your own number.
Special kinds appear in the tiles when they apply. A twin prime has another prime 2 away. A Sophie Germain prime p has 2p + 1 prime too, and that 2p + 1 is a safe prime: 5 and 23 are both. A Mersenne prime is one less than a power of 2, such as 127. A Fermat prime is one more than 2 raised to a power of 2. Only five are known: 3, 5, 17, 257 and 65,537.
Common mistakes
- Calling 1 a prime. A prime has exactly two divisors, and 1 has one. Counting it would let every number factor in endless ways, such as 6 = 2 × 3 × 1 × 1.
- Stopping at the quick rules. The tests for 2, 3 and 5 miss numbers like 91, 119 and 133, which are 7 times 13, 7 times 17 and 7 times 19.
- Trusting a Fermat test alone. 561 passes Fermat's test for every base that shares no factor with it, yet it is 3 × 11 × 17. Numbers like this are Carmichael numbers. Trial division finds its factor 3 at once.
- Testing every number up to n. You only need the primes up to the square root. Past that, any factor you find pairs with a smaller one you have already tried.
Questions people ask
Sources
- OEIS A000040, The prime numbers
- OEIS A014233, Smallest odd number that is a strong pseudoprime to the first n prime bases
- J. Sorenson and J. Webster, Strong Pseudoprimes to Twelve Prime Bases (arXiv 1509.00864)
- MathWorld, Fermat's Little Theorem
- OEIS A002997, Carmichael numbers
- OEIS A006880, Number of primes below 10^n
- OEIS A033874, 10^n minus the largest prime below 10^n
- OEIS A019434, Fermat primes