Check Prime Numbers
Check if any number is prime using the deterministic Miller-Rabin algorithm. Instant primality test with factorization for composite numbers.
About
A miscounted prime breaks RSA key generation. A wrong factorization invalidates a cryptographic proof. This tool applies the deterministic Miller-Rabin primality test with witness set [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37] to produce a guaranteed correct result for any integer n < 3.317 Γ 1024. For composite inputs, the tool returns the complete prime factorization via trial division combined with Pollard's Rho algorithm. Results are deterministic, not probabilistic. The tool handles arbitrarily large integers through JavaScript BigInt arithmetic.
Limitation: for integers exceeding 1018, factorization of large composite numbers may take several seconds if the number has two very large prime factors. The primality verdict itself remains instant regardless of size. Pro tip: when verifying Mersenne primes of the form 2p β 1, first confirm that p itself is prime.
Formulas
The Miller-Rabin test expresses n β 1 as 2s β d where d is odd, then checks witnesses:
For each witness a, compute:
If x = 1 or x = n β 1, the number passes for this witness. Otherwise, square x up to s β 1 times:
If x never reaches n β 1, then n is composite. The Prime Number Theorem gives the approximate count of primes below n:
Where Ο(n) is the prime-counting function and ln is the natural logarithm. For factorization of composite numbers, Pollard's Rho uses the iteration x β x2 + c mod n with Floyd's cycle detection to find gcd(|x β y|, n) > 1.
Reference Data
| Range | Count of Primes | Prime Density | Largest Prime in Range |
|---|---|---|---|
| 1 - 10 | 4 | 40.0% | 7 |
| 1 - 100 | 25 | 25.0% | 97 |
| 1 - 1,000 | 168 | 16.8% | 997 |
| 1 - 10,000 | 1,229 | 12.29% | 9,973 |
| 1 - 100,000 | 9,592 | 9.59% | 99,991 |
| 1 - 1,000,000 | 78,498 | 7.85% | 999,983 |
| 1 - 10,000,000 | 664,579 | 6.65% | 9,999,991 |
| 1 - 108 | 5,761,455 | 5.76% | 99,999,989 |
| 1 - 109 | 50,847,534 | 5.08% | 999,999,937 |
| 1 - 1010 | 455,052,511 | 4.55% | 9,999,999,967 |
| Notable Primes | |||
| Largest known twin prime | 2,996,863,034,895 Γ 21,290,000 Β± 1 (388,342 digits) | ||
| Largest known Mersenne prime | 2136,279,841 β 1 (41,024,320 digits, M52) | ||
| First 20 primes | 2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71 | ||
| Mersenne exponents | 2, 3, 5, 7, 13, 17, 19, 31, 61, 89, 107, 127, 521, 607 | ||
| Fermat primes (known) | 3, 5, 17, 257, 65537 | ||