Why 1 is not prime. The convention excludes 1 to make the fundamental theorem of arithmetic clean: every integer >1 factors uniquely into primes. If 1 were prime, 6=2⋅3=1⋅2⋅3=1⋅1⋅2⋅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 that are not prime are composite. Examples: 4=2⋅2, 6=2⋅3, 8=23, 9=32, 10=2⋅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=22⋅3,100=22⋅52,420=22⋅3⋅5⋅7,1000000=26⋅56
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], we have 6=2⋅3=(1+−5)(1−−5) — two different factorizations into irreducibles. The integers Z have unique factorization; this is a deep property requiring proof.
Proof sketch. Standard proofs use the Euclidean algorithm: if a prime p divides a product ab, then p divides a or p divides b. 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) time. • List a range — direct slice, O(b−a) time. • Membership test — hash-set lookup, O(1) time. • $n$-th prime lookup — direct array access, O(1) time.
Out-of-range behavior. For inputs m>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 m≈105 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 m by all primes up to m. Slow but exact. Practical up to ∼1012. • 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 (2p−1). Used by GIMPS to find the largest known primes.
The largest known prime (as of recent record): 282,589,933−1, a Mersenne prime with over 24 million digits. Found via GIMPS in 2018.
The Prime Counting Function and Distribution
Let π(x) denote the number of primes less than or equal to x. Examples:
Equivalently, the density of primes near x is approximately 1/lnx. So:
• Near x=1000, about 1 in 7 numbers is prime. • Near x=106, about 1 in 14 numbers is prime. • Near x=10100, 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 approximates π(x) more accurately than x/lnx. For x=1015, Li(x) matches π(x) to within about 107 (out of ∼3⋅1013 primes).
The Riemann hypothesis. The conjecture that all non-trivial zeros of the Riemann zeta function ζ(s) lie on the line Re(s)=1/2 would give very precise error bounds on π(x)−Li(x), namely O(xlnx). This is the most famous open problem in mathematics.
Inverse: the $n$-th prime.pn∼nlnn. Examples: p100=541≈100⋅ln100=460; p1000=7919≈1000⋅ln1000=6908. The approximation improves for large n and can be refined using pn≈n(lnn+lnlnn−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) both prime: (3,5),(5,7),(11,13),(17,19),(29,31),…. 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 4⋅1018; no proof. Examples: 4=2+2, 6=3+3, 8=3+5, 10=3+7=5+5, 100=3+97=11+89=….
Riemann hypothesis. All non-trivial zeros of ζ(s) have real part 1/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 2p−1 where p is prime: 3,7,31,127,8191,…. Open: are there infinitely many? GIMPS finds new ones occasionally; only 51 known.
Fermat primes. Primes of the form 22n+1: 3,5,17,257,65537. Only these five known; conjectured to be the only ones.
Sophie Germain primes. Primes p such that 2p+1 is also prime. 2,3,5,11,23,29,41,…. Open: infinitely many?
Bertrand's postulate (proved): for every n≥1, there is a prime p with n<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 p and q (each typically 1024 bits). Their product N=pq is the public modulus. The security of RSA rests on the difficulty of factoring N back into p and q when only N is given.
• Encryption: given a message m and a public key (N,e), compute c=memodN. • Decryption: with the private key d (derived from ϕ(N)=(p−1)(q−1)), compute m=cdmodN.
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 p and a generator g of the multiplicative group modulo p. Two parties exchange gamodp and gbmodp publicly; both can compute the shared secret gabmodp 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 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 p 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), the distribution is irregular: prime gaps can be small (twin primes) or large (gaps growing as logpn on average, but with occasional very large gaps).
• Conflating prime with irreducible. In the integers Z, prime and irreducible are equivalent. In more general algebraic settings, they can differ. Always specify "in Z" when needed.
• Over-trusting trial division for large numbers. Trial division up to N is exact but slow for N above ∼1012. Use Miller-Rabin or AKS for larger inputs.
• Forgetting Wilson's theorem subtleties.(p−1)!≡−1(modp) for prime p 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 is a sum of three primes — was settled (Helfgott 2013, building on Vinogradov).
• Mersenne-Fermat prime confusion. Mersenne: 2p−1. Fermat: 22n+1. Different forms, different open problems.
Related Sequences and Concepts
Composite Numbers — the integers >1 that are not prime: 4, 6, 8, 9, 10, 12, ... The complement of the prime sequence.