Visual Tools
Calculators
Tables
Mathematical Keyboard
Converters
Other Tools

Prime Numbers Calculator






What is a Prime Number?

A prime number is a positive integer greater than 1 whose only positive divisors are 1 and itself. The first few primes:

2,3,5,7,11,13,17,19,23,29,31,37,41,43,47,53,59,61,67,71,73,79,83,89,97,2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71, 73, 79, 83, 89, 97, \ldots


Why 1 is not prime. The convention excludes 1 to make the fundamental theorem of arithmetic clean: every integer >1> 1 factors uniquely into primes. If 1 were prime, 6=23=123=11236 = 2 \cdot 3 = 1 \cdot 2 \cdot 3 = 1 \cdot 1 \cdot 2 \cdot 3 would have multiple representations.

Why 2 is the only even prime. Every other even number is divisible by 2, so cannot be prime. Both being even and being greater than 2 implies non-prime.

Composite numbers. Integers >1> 1 that are not prime are composite. Examples: 4=224 = 2 \cdot 2, 6=236 = 2 \cdot 3, 8=238 = 2^3, 9=329 = 3^2, 10=2510 = 2 \cdot 5.

Scope of this explorer. This tool uses a precomputed list of the first 10,000 primes, with maximum value 104,729 (the 10,000th prime). Lookups and membership tests within this range are constant-time. For larger numbers, dedicated primality-testing tools are needed.

For deeper coverage see prime number, fundamental theorem of arithmetic, and primality test.

The Fundamental Theorem of Arithmetic

Statement. Every integer greater than 1 either is prime or can be written uniquely (up to ordering) as a product of primes.

For example:

12=223,100=2252,420=22357,1000000=265612 = 2^2 \cdot 3, \quad 100 = 2^2 \cdot 5^2, \quad 420 = 2^2 \cdot 3 \cdot 5 \cdot 7, \quad 1000000 = 2^6 \cdot 5^6


Why uniqueness matters. Unique factorization is what makes primes "atoms" of arithmetic. The integers have a structure as a unique factorization domain — properties like greatest common divisor, least common multiple, modular arithmetic, and modular inverses all rest on this structure.

Why it's a theorem, not a definition. It's not obvious that factorization is unique. Consider analogous systems where it fails: in Z[5]\mathbb{Z}[\sqrt{-5}], we have 6=23=(1+5)(15)6 = 2 \cdot 3 = (1 + \sqrt{-5})(1 - \sqrt{-5}) — two different factorizations into irreducibles. The integers Z\mathbb{Z} have unique factorization; this is a deep property requiring proof.

Proof sketch. Standard proofs use the Euclidean algorithm: if a prime pp divides a product abab, then pp divides aa or pp divides bb. This "prime property" plus induction gives unique factorization.

Practical consequence. All number-theoretic algorithms (GCD computation, modular inverse, RSA, primality testing) rest on the structure that the fundamental theorem provides. Disrupt unique factorization and most of cryptography breaks down.

Primality Testing — How the Explorer Decides

This explorer uses a precomputed list of the first 10,000 primes (up to 104,729). Three modes interact with the list:

Browse the first $N$ primes — direct array access, O(N)O(N) time.
List a range — direct slice, O(ba)O(b - a) time.
Membership test — hash-set lookup, O(1)O(1) time.
$n$-th prime lookup — direct array access, O(1)O(1) time.

Out-of-range behavior. For inputs m>104,729m > 104{,}729, the explorer reports the value as out of range rather than guessing. To test primality of larger numbers, use dedicated primality-testing tools or libraries.

Why precomputed. Storing the first 10,000 primes costs only a few kilobytes of memory and gives constant-time answers for the common range of educational and recreational queries. Naive trial division for m105m \approx 10^5 would require dozens of divisions per query — not slow, but slower than a lookup.

General-case primality tests (for context, not used here):

Trial division: divide mm by all primes up to m\sqrt{m}. Slow but exact. Practical up to 1012\sim 10^{12}.
Miller-Rabin: probabilistic test, fast and very reliable. Practical for thousands of digits.
AKS primality test: deterministic polynomial-time test (2002). Theoretically important but slower than Miller-Rabin in practice.
Lucas-Lehmer: specialized test for Mersenne primes (2p12^p - 1). Used by GIMPS to find the largest known primes.

The largest known prime (as of recent record): 282,589,93312^{82,589,933} - 1, a Mersenne prime with over 24 million digits. Found via GIMPS in 2018.

The Prime Counting Function and Distribution

Let π(x)\pi(x) denote the number of primes less than or equal to xx. Examples:

π(10)=4,π(100)=25,π(1000)=168,π(10000)=1229,π(100000)=9592\pi(10) = 4, \quad \pi(100) = 25, \quad \pi(1000) = 168, \quad \pi(10000) = 1229, \quad \pi(100000) = 9592


The prime number theorem (PNT). π(x)xlnx\pi(x) \sim \dfrac{x}{\ln x} as xx \to \infty.

Equivalently, the density of primes near xx is approximately 1/lnx1/\ln x. So:

• Near x=1000x = 1000, about 1 in 7 numbers is prime.
• Near x=106x = 10^6, about 1 in 14 numbers is prime.
• Near x=10100x = 10^{100}, about 1 in 230 numbers is prime.

Primes become sparser as numbers grow, but never disappear (Euclid's theorem).

Better approximations. The logarithmic integral Li(x)=2xdt/lnt\text{Li}(x) = \int_2^x dt/\ln t approximates π(x)\pi(x) more accurately than x/lnxx / \ln x. For x=1015x = 10^{15}, Li(x)\text{Li}(x) matches π(x)\pi(x) to within about 10710^7 (out of 31013\sim 3 \cdot 10^{13} primes).

The Riemann hypothesis. The conjecture that all non-trivial zeros of the Riemann zeta function ζ(s)\zeta(s) lie on the line Re(s)=1/2\text{Re}(s) = 1/2 would give very precise error bounds on π(x)Li(x)\pi(x) - \text{Li}(x), namely O(xlnx)O(\sqrt{x} \ln x). This is the most famous open problem in mathematics.

Inverse: the $n$-th prime. pnnlnnp_n \sim n \ln n. Examples: p100=541100ln100=460p_{100} = 541 \approx 100 \cdot \ln 100 = 460; p1000=79191000ln1000=6908p_{1000} = 7919 \approx 1000 \cdot \ln 1000 = 6908. The approximation improves for large nn and can be refined using pnn(lnn+lnlnn1)p_n \approx n(\ln n + \ln \ln n - 1).

Famous Conjectures and Open Problems

Despite their elementary definition, primes harbor some of the deepest open problems in mathematics.

Twin prime conjecture. Twin primes are pairs (p,p+2)(p, p + 2) both prime: (3,5),(5,7),(11,13),(17,19),(29,31),(3, 5), (5, 7), (11, 13), (17, 19), (29, 31), \ldots. Open question: are there infinitely many twin primes? Likely yes; proof remains elusive. The Polymath project and Yitang Zhang's 2013 breakthrough proved infinitely many primes differ by at most some bounded amount; the bound has been reduced to 246 (and conditionally to 6 under stronger hypotheses).

Goldbach conjecture. Every even integer greater than 2 is a sum of two primes. Verified computationally up to 410184 \cdot 10^{18}; no proof. Examples: 4=2+24 = 2 + 2, 6=3+36 = 3 + 3, 8=3+58 = 3 + 5, 10=3+7=5+510 = 3 + 7 = 5 + 5, 100=3+97=11+89=100 = 3 + 97 = 11 + 89 = \ldots.

Riemann hypothesis. All non-trivial zeros of ζ(s)\zeta(s) have real part 1/21/2. Equivalent to precise error bounds on the distribution of primes. One of the Millennium Prize Problems (\1$ million for a proof).

Mersenne primes. Primes of the form 2p12^p - 1 where pp is prime: 3,7,31,127,8191,3, 7, 31, 127, 8191, \ldots. Open: are there infinitely many? GIMPS finds new ones occasionally; only 51 known.

Fermat primes. Primes of the form 22n+12^{2^n} + 1: 3,5,17,257,655373, 5, 17, 257, 65537. Only these five known; conjectured to be the only ones.

Sophie Germain primes. Primes pp such that 2p+12p + 1 is also prime. 2,3,5,11,23,29,41,2, 3, 5, 11, 23, 29, 41, \ldots. Open: infinitely many?

Bertrand's postulate (proved): for every n1n \geq 1, there is a prime pp with n<p<2nn < p < 2n. Erdős gave an elegant proof at age 19.

Green-Tao theorem (2004): the primes contain arbitrarily long arithmetic progressions. A landmark result with surprising structural depth.

Primes in Cryptography

Primes are the foundation of modern public-key cryptography. Two prominent schemes:

RSA encryption. A user picks two large primes pp and qq (each typically 1024 bits). Their product N=pqN = p q is the public modulus. The security of RSA rests on the difficulty of factoring NN back into pp and qq when only NN is given.

Encryption: given a message mm and a public key (N,e)(N, e), compute c=memodNc = m^e \bmod N.
Decryption: with the private key dd (derived from ϕ(N)=(p1)(q1)\phi(N) = (p - 1)(q - 1)), compute m=cdmodNm = c^d \bmod N.

Breaking RSA is equivalent to factoring large semi-primes. The best classical algorithms (general number field sieve) are sub-exponential; quantum computers running Shor's algorithm could factor in polynomial time, motivating post-quantum cryptography.

Diffie-Hellman key exchange. Uses a large prime pp and a generator gg of the multiplicative group modulo pp. Two parties exchange gamodpg^a \bmod p and gbmodpg^b \bmod p publicly; both can compute the shared secret gabmodpg^{ab} \bmod p but an eavesdropper cannot (under the discrete log assumption).

Why primality matters. Both schemes require generating large primes quickly. Probabilistic primality tests (Miller-Rabin) verify candidate primes in milliseconds; the prime number theorem says about 1 in ln(N)1000\ln(N) \approx 1000 random 1000-bit numbers is prime, so a few thousand candidates produce a usable prime.

Why primality is necessary. The mathematical structure (cyclic groups, modular inverses, Fermat's little theorem) requires primes or carefully chosen prime-related moduli. Replacing pp with a composite breaks the algorithms in subtle but devastating ways.

Post-quantum cryptography. Lattice-based, code-based, and hash-based schemes aim to replace RSA and Diffie-Hellman without relying on factoring or discrete logs. Active area of standardization (NIST).

Common Mistakes

Calling 1 a prime. By modern convention, 1 is neither prime nor composite. Historical mathematicians sometimes called it prime, but the convention shifted in the 19th-20th century for clarity of unique factorization.

Calling 2 not prime because it's even. 2 is the unique even prime. Its evenness is a quirk, not a disqualifier.

Thinking primes thin out predictably. While density decreases (1/lnx\sim 1/\ln x), the distribution is irregular: prime gaps can be small (twin primes) or large (gaps growing as logpn\log p_n on average, but with occasional very large gaps).

Conflating prime with irreducible. In the integers Z\mathbb{Z}, prime and irreducible are equivalent. In more general algebraic settings, they can differ. Always specify "in Z\mathbb{Z}" when needed.

Over-trusting trial division for large numbers. Trial division up to N\sqrt{N} is exact but slow for NN above 1012\sim 10^{12}. Use Miller-Rabin or AKS for larger inputs.

Forgetting Wilson's theorem subtleties. (p1)!1(modp)(p - 1)! \equiv -1 \pmod p for prime pp is a beautiful characterization but impractical as a primality test (the factorial grows too fast).

Misremembering Goldbach. Goldbach's conjecture is about even integers, not all integers. The corresponding statement for odd integers — every odd 7\geq 7 is a sum of three primes — was settled (Helfgott 2013, building on Vinogradov).

Mersenne-Fermat prime confusion. Mersenne: 2p12^p - 1. Fermat: 22n+12^{2^n} + 1. Different forms, different open problems.

Related Sequences and Concepts

Composite Numbers — the integers >1> 1 that are not prime: 4, 6, 8, 9, 10, 12, ... The complement of the prime sequence.

Twin Primes — pairs (p,p+2)(p, p+2) both prime: (3,5), (5,7), (11,13), (17,19), ... Conjectured infinite.

Mersenne Primes — primes of the form 2p12^p - 1: 3, 7, 31, 127, 8191, ... Only 51 known. The largest known primes are Mersenne primes.

Fermat Primes — primes of the form 22n+12^{2^n} + 1: 3, 5, 17, 257, 65537. Only five known.

Sophie Germain Primes — primes pp with 2p+12p + 1 also prime: 2, 3, 5, 11, 23, ...

Safe Primes — primes of the form 2p+12p + 1 where pp is prime (the partner of Sophie Germain primes).

Pi Function $\pi(x)$ — counts primes up to xx. Asymptotically x/lnx\sim x / \ln x (PNT).

Riemann Zeta Functionζ(s)=1/ns\zeta(s) = \sum 1/n^s for Re(s)>1\text{Re}(s) > 1, extended analytically. The Riemann hypothesis about its zeros is the central open problem.

Goldbach Conjecture — every even integer >2> 2 is a sum of two primes. Verified to 410184 \cdot 10^{18}; unproven.

Fundamental Theorem of Arithmetic — every integer >1> 1 factors uniquely into primes.

Euclidean Algorithm — the algorithm for computing GCDs; depends on (and proves) the prime property.

Modular Arithmetic — arithmetic modulo nn. Behaves well when nn is prime; factor primes determine structure for general nn.

Wilson's Theorem(p1)!1(modp)(p-1)! \equiv -1 \pmod p if and only if pp is prime.

Fermat's Little Theoremapa(modp)a^p \equiv a \pmod p for any integer aa and prime pp. Used in Fermat primality testing.

Miller-Rabin Test — the standard probabilistic primality test, based on Fermat's little theorem.

AKS Primality Test — the first deterministic polynomial-time primality test (2002).

RSA Cryptography — public-key cryptosystem based on the difficulty of factoring products of large primes.

Sieve of Eratosthenes — the classical algorithm for listing primes up to NN. Time complexity O(NloglogN)O(N \log \log N) — very fast for moderate NN.

Prime Gaps — the differences pn+1pnp_{n+1} - p_n. The largest known prime gaps are surprisingly large; the average is lnpn\sim \ln p_n.

Green-Tao Theorem — the primes contain arbitrarily long arithmetic progressions.