How primality is checked
A prime number is a whole number greater than 1 whose only factors are 1 and itself. To test one:
- Divide by the primes up to 1,009. If one divides evenly, the number isn't prime. If none do and the number is below 1,026,169 (that's 1,013²), it is prime.
- Otherwise run the Miller–Rabin test using the first 13 primes (2 to 41) as bases. It has been proven that no composite number below 3.3 × 10²⁴ passes all 13, so for every 64-bit number, and well beyond, the answer is certain.
- For even larger numbers (up to 100 digits), the test uses 40 bases. No composite is known that passes, but this is a probable-prime test, and the result says so.
Worked examples
- 97: √97 ≈ 9.85, and none of 2, 3, 5 or 7 divides 97, so it's prime.
- 91: 91 = 7 × 13, so it's not prime, even though it looks like it might be.
- 561: 561 = 3 × 11 × 17. It's the smallest Carmichael number, which fools the simpler Fermat test, but Miller–Rabin catches it.
- 2,305,843,009,213,693,951: that's 2⁶¹ − 1, a Mersenne prime, confirmed instantly.
How many primes are there?
| Up to | Number of primes |
|---|---|
| 100 | 25 |
| 1,000 | 168 |
| 10,000 | 1,229 |
| 100,000 | 9,592 |
| 1,000,000 | 78,498 |
Primes thin out slowly: near a number n, roughly 1 in every ln(n) numbers is prime. There are infinitely many of them, as Euclid proved.
Limits
- Single numbers: up to 100 digits. Answers are proven for numbers below 3.3 × 10²⁴ and probable above that.
- Ranges: up to 1,000,000 numbers wide when the numbers are below 1012, or 10,000 wide above that. Up to 1,000 primes are listed, but the count is always complete.
- Full factorizations are shown for numbers below 1019; see the factor calculator.
Sources
- OEIS A014233: smallest odd numbers that pass Miller–Rabin for the first n prime bases
- Sorenson and Webster, “Strong pseudoprimes to twelve prime bases,” Mathematics of Computation (2017), which proves the 13-base bound
- Wolfram MathWorld: Miller–Rabin strong pseudoprime test
- OEIS A006880: number of primes below 10ⁿ