Visual Tools
Calculators
Tables
Mathematical Keyboard
Converters
Other Tools


Prime Numbers






Integers with Exactly Two Factors

The prime numbers are the building blocks of the integers: every integer greater than 11 is either prime or can be expressed as a product of primes. Unlike every other sequence in this section, the primes obey no algebraic formula — there is no expression that computes the nn-th prime from nn. What is known about their distribution comes from deep results in number theory rather than from explicit pattern recognition.



Definition

A prime number is an integer greater than 11 whose only positive divisors are 11 and itself. A composite number is an integer greater than 11 that has at least one positive divisor other than 11 and itself. Every integer greater than 11 is exactly one of these two types.

The first primes are:

2,3,5,7,11,13,17,19,23,29,31,37,41,43,47,2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, \ldots


The number 22 is the only even prime — every other even number is divisible by 22 and therefore composite. The number 11 is neither prime nor composite: it has exactly one positive divisor (itself), while primes are required to have exactly two.

The exclusion of 11 is not arbitrary. If 11 were prime, the fundamental theorem of arithmetic would fail: 1212 could be factored as 2232^2 \cdot 3 or 12231 \cdot 2^2 \cdot 3 or 152231^5 \cdot 2^2 \cdot 3, and uniqueness of prime factorization would be lost.

Infinitude of Primes

There are infinitely many prime numbers. Euclid's proof, over two thousand years old, is one of the most celebrated arguments in all of mathematics.

Assume, for contradiction, that only finitely many primes exist: p1,p2,,pkp_1, p_2, \ldots, p_k. Form the number:

N=p1p2p3pk+1N = p_1 \cdot p_2 \cdot p_3 \cdots p_k + 1


Dividing NN by any prime pip_i on the list leaves a remainder of 11, so NN is not divisible by any of the listed primes. Either NN is itself prime (a prime missing from the list) or NN has a prime factor not on the list. In either case, the original list is incomplete.

The argument does not claim that NN is prime — it claims that NN has a prime factor outside the assumed list. For instance, 23571113+1=30031=595092 \cdot 3 \cdot 5 \cdot 7 \cdot 11 \cdot 13 + 1 = 30031 = 59 \cdot 509, which is composite, but its factors 5959 and 509509 are primes not in the original set.

No finite collection of primes can account for all of them. New primes always exist beyond any boundary.

The Sieve of Eratosthenes

The sieve of Eratosthenes is a systematic algorithm for finding all primes up to a given limit nn.

Start with a list of integers from 22 to nn. The smallest unmarked number is 22 — it is prime. Cross out every multiple of 22 (i.e., 4,6,8,10,4, 6, 8, 10, \ldots). The next unmarked number is 33 — it is prime. Cross out every multiple of 33 that has not already been crossed out (9,15,21,9, 15, 21, \ldots; note 6,12,186, 12, 18 are already gone). Continue: the next unmarked number is 55, cross out its multiples, and so on.

The process stops once the current prime exceeds n\sqrt{n}. Any composite number n\leq n must have a factor n\leq \sqrt{n}, so if it were not already eliminated, one of its factors would have crossed it out in an earlier pass.

For n=30n = 30: start with 2,3,4,5,,302, 3, 4, 5, \ldots, 30. After sieving by 22: all even numbers >2> 2 are removed. After 33: 9,15,21,279, 15, 21, 27 are removed. After 55: 2525 is removed. Since 30<6\sqrt{30} < 6, the process ends. The surviving numbers 2,3,5,7,11,13,17,19,23,292, 3, 5, 7, 11, 13, 17, 19, 23, 29 are all primes up to 3030.

Primality Testing

To determine whether a single integer nn is prime, the most direct method is trial division: test whether nn is divisible by any integer from 22 to n\lfloor \sqrt{n} \rfloor.

The bound n\sqrt{n} is sufficient because if n=abn = ab with aba \leq b, then ana \leq \sqrt{n}. Any factor at or below the square root will be caught; any factor above it has a complementary factor below it.

Efficiency improves by skipping even numbers after checking 22: if nn is not divisible by 22, it cannot be divisible by 4,6,8,4, 6, 8, \ldots. Checking only 22 and odd numbers up to n\sqrt{n} cuts the work roughly in half. Further savings come from checking only 2,32, 3, and numbers of the form 6k±16k \pm 1, since every prime greater than 33 has this form.

Is 9797 prime? 97<10\sqrt{97} < 10, so check divisibility by 2,3,5,72, 3, 5, 7. None divide 9797, so it is prime.

Is 9191 prime? Check 22 (no), 33 (no), 55 (no), 77: 91=7×1391 = 7 \times 13. It is composite.

Trial division works well for numbers up to several digits. For very large numbers — the kind used in cryptography — more advanced methods exist, but they are beyond the scope of this page.

Prime Factorization

The fundamental theorem of arithmetic states that every integer greater than 11 can be expressed as a product of prime numbers, and this factorization is unique up to the order of the factors.

60=2235,360=23325,1001=7111360 = 2^2 \cdot 3 \cdot 5, \quad 360 = 2^3 \cdot 3^2 \cdot 5, \quad 1001 = 7 \cdot 11 \cdot 13


No matter how the factorization is carried out — whether starting by dividing out 22s or by noticing that 1001=7×1431001 = 7 \times 143 — the final set of prime factors and their multiplicities is always the same.

Finding the factorization uses repeated division by the smallest available prime. Divide nn by 22 as many times as possible, then by 33, then by 55, and so on. For 252252: 252÷2=126252 \div 2 = 126, 126÷2=63126 \div 2 = 63, 63÷3=2163 \div 3 = 21, 21÷3=721 \div 3 = 7, and 77 is prime. So 252=22327252 = 2^2 \cdot 3^2 \cdot 7.

Prime factorization connects directly to the GCD and LCM. Given the factorizations of two numbers, the GCD takes the minimum power of each shared prime, and the LCM takes the maximum power of each prime that appears in either factorization.

The Prime Number Theorem

Although primes are infinite, they become rarer among larger integers. Among the first 100100 integers, 2525 are prime. Among the first 1,0001{,}000, only 168168. Among the first 1,000,0001{,}000{,}000, only 78,49878{,}498.

The prime number theorem makes this thinning precise. Let π(n)\pi(n) denote the number of primes less than or equal to nn. Then:

π(n)nlnn\pi(n) \approx \frac{n}{\ln n}


as nn grows large. The approximation improves in relative terms: the ratio π(n)n/lnn\frac{\pi(n)}{n / \ln n} approaches 11.

The practical interpretation is that near a large number nn, roughly one in every lnn\ln n integers is prime. Near n=1,000,000n = 1{,}000{,}000, the average gap between consecutive primes is about ln(106)13.8\ln(10^6) \approx 13.8. Near n=1012n = 10^{12}, it is about 27.627.6. Primes spread further apart on average but never disappear.

The prime number theorem was conjectured by Gauss and Legendre in the late 18th century and proved independently by Hadamard and de la Vallée-Poussin in 1896.

Types of Primes

Certain primes satisfy additional structural constraints, leading to named families.

Mersenne primes have the form 2p12^p - 1, where pp itself must be prime (though not every prime pp produces a Mersenne prime). The first Mersenne primes are 3,7,31,1273, 7, 31, 127 (corresponding to p=2,3,5,7p = 2, 3, 5, 7). The exponent p=11p = 11 gives 2111=2047=23×892^{11} - 1 = 2047 = 23 \times 89, which is composite. The largest known primes are typically Mersenne primes, found by specialized search algorithms.

Fermat primes have the form 22n+12^{2^n} + 1. Only five are known: 3,5,17,257,655373, 5, 17, 257, 65537 (for n=0,1,2,3,4n = 0, 1, 2, 3, 4). Fermat conjectured that all numbers of this form are prime; Euler disproved this by showing 225+1=4294967297=641×67004172^{2^5} + 1 = 4294967297 = 641 \times 6700417.

Twin primes are pairs of primes that differ by 22: (3,5)(3, 5), (5,7)(5, 7), (11,13)(11, 13), (17,19)(17, 19), (29,31)(29, 31). Whether infinitely many twin prime pairs exist remains one of the oldest open problems in mathematics — the twin prime conjecture is widely believed true but unproven.

Sophie Germain primes are primes pp for which 2p+12p + 1 is also prime. The first examples are 2,3,5,11,23,29,412, 3, 5, 11, 23, 29, 41. These primes play a role in primality testing algorithms and in the theory of safe primes used in cryptography.