# Prime number

A **prime number** (or a **prime**) is a natural number greater than 1 that is not a product of two smaller natural numbers. A natural number greater than 1 that is not prime is called a composite number. For example, 5 is prime because the only ways of writing it as a product, 1 × 5 or 5 × 1, involve 5 itself.
However, 4 is composite because it is a product (2 × 2) in which both numbers are smaller than 4. Primes are central in number theory because of the fundamental theorem of arithmetic: every natural number greater than 1 is either a prime itself or can be factorized as a product of primes that is unique up to their order.

There are infinitely many primes, as demonstrated by Euclid around 300 BC. No known simple formula separates prime numbers from composite numbers. However, the distribution of primes within the natural numbers in the large can be statistically modelled. The first result in that direction is the prime number theorem, proven at the end of the 19th century, which says that the probability of a randomly chosen large number being prime is inversely proportional to its number of digits, that is, to its logarithm.

Several historical questions regarding prime numbers are still unsolved. These include Goldbach's conjecture, that every even integer greater than 2 can be expressed as the sum of two primes, and the twin prime conjecture, that there are infinitely many pairs of primes having just one even number between them. Such questions spurred the development of various branches of number theory, focusing on analytic or algebraic aspects of numbers. Primes are used in several routines in information technology, such as public-key cryptography, which relies on the difficulty of factoring large numbers into their prime factors. In abstract algebra, objects that behave in a generalized way like prime numbers include prime elements and prime ideals.

The first 25 prime numbers (all the prime numbers less than 100) are:^{[8]}

The Rhind Mathematical Papyrus, from around 1550 BC, has Egyptian fraction expansions of different forms for prime and composite numbers.^{[13]} However, the earliest surviving records of the explicit study of prime numbers come from ancient Greek mathematics. Euclid's *Elements* (c. 300 BC) proves the infinitude of primes and the fundamental theorem of arithmetic, and shows how to construct a perfect number from a Mersenne prime.^{[14]} Another Greek invention, the Sieve of Eratosthenes, is still used to construct lists of primes.^{[15]}^{[16]}

Many mathematicians have worked on primality tests for numbers larger than those where trial division is practicably applicable. Methods that are restricted to specific number forms include Pépin's test for Fermat numbers (1877),^{[26]} Proth's theorem (c. 1878),^{[27]} the Lucas–Lehmer primality test (originated 1856), and the generalized Lucas primality test.^{[16]}

Since 1951 all the largest known primes have been found using these tests on computers.^{[a]} The search for ever larger primes has generated interest outside mathematical circles, through the Great Internet Mersenne Prime Search and other distributed computing projects.^{[8]}^{[29]} The idea that prime numbers had few applications outside of pure mathematics^{[b]} was shattered in the 1970s when public-key cryptography and the RSA cryptosystem were invented, using prime numbers as their basis.^{[32]}

The increased practical importance of computerized primality testing and factorization led to the development of improved methods capable of handling large numbers of unrestricted form.^{[15]}^{[33]}^{[34]} The mathematical theory of prime numbers also moved forward with the Green–Tao theorem (2004) that there are arbitrarily long arithmetic progressions of prime numbers, and Yitang Zhang's 2013 proof that there exist infinitely many prime gaps of bounded size.^{[35]}

Most early Greeks did not even consider 1 to be a number,^{[36]}^{[37]} so they could not consider its primality. A few scholars in the Greek and later Roman tradition, including Nicomachus, Iamblichus, Boethius, and Cassiodorus also considered the prime numbers to be a subdivision of the odd numbers, so they did not consider 2 to be prime either. However, Euclid and a majority of the other Greek mathematicians considered 2 as prime. The medieval Islamic mathematicians largely followed the Greeks in viewing 1 as not being a number.^{[36]}
By the Middle Ages and Renaissance, mathematicians began treating 1 as a number, and some of them included it as the first prime number.^{[38]} In the mid-18th century Christian Goldbach listed 1 as prime in his correspondence with Leonhard Euler; however, Euler himself did not consider 1 to be prime.^{[39]} In the 19th century many mathematicians still considered 1 to be prime,^{[40]} and lists of primes that included 1 continued to be published as recently as 1956.^{[41]}^{[42]}

If the definition of a prime number were changed to call 1 a prime, many statements involving prime numbers would need to be reworded in a more awkward way. For example, the fundamental theorem of arithmetic would need to be rephrased in terms of factorizations into primes greater than 1, because every number would have multiple factorizations with different numbers of copies of 1.^{[40]} Similarly, the sieve of Eratosthenes would not work correctly if it handled 1 as a prime, because it would eliminate all multiples of 1 (that is, all other numbers) and output only the single number 1.^{[42]} Some other more technical properties of prime numbers also do not hold for the number 1: for instance, the formulas for Euler's totient function or for the sum of divisors function are different for prime numbers than they are for 1.^{[43]} By the early 20th century, mathematicians began to agree that 1 should not be listed as prime, but rather in its own special category as a "unit".^{[40]}

Writing a number as a product of prime numbers is called a *prime factorization* of the number. For example:

The central importance of prime numbers to number theory and mathematics in general stems from the *fundamental theorem of arithmetic*.^{[44]} This theorem states that every integer larger than 1 can be written as a product of one or more primes. More strongly,
this product is unique in the sense that any two prime factorizations of the same number will have the same numbers of copies of the same primes,
although their ordering may differ.^{[45]} So, although there are many different ways of finding a factorization using an integer factorization algorithm, they all must produce the same result. Primes can thus be considered the "basic building blocks" of the natural numbers.^{[46]}

There are infinitely many prime numbers. Another way of saying this is that the sequence

of prime numbers never ends. This statement is referred to as *Euclid's theorem* in honor of the ancient Greek mathematician Euclid, since the first known proof for this statement is attributed to him. Many more proofs of the infinitude of primes are known, including an analytical proof by Euler, Goldbach's proof based on Fermat numbers,^{[49]} Furstenberg's proof using general topology,^{[50]} and Kummer's elegant proof.^{[51]}

The numbers formed by adding one to the products of the smallest primes are called Euclid numbers.^{[53]} The first five of them are prime, but the sixth,

There is no known efficient formula for primes. For example, there is no non-constant polynomial, even in several variables, that takes *only* prime values.^{[54]} However, there are numerous expressions that do encode all primes, or only primes. One possible formula is based on Wilson's theorem and generates the number 2 many times and all other primes exactly once.^{[55]} There is also a set of Diophantine equations in nine variables and one parameter with the following property: the parameter is prime if and only if the resulting system of equations has a solution over the natural numbers. This can be used to obtain a single formula with the property that all its *positive* values are prime.^{[54]}

Analytic number theory studies number theory through the lens of continuous functions, limits, infinite series, and the related mathematics of the infinite and infinitesimal.

The distribution of primes in the large, such as the question how many primes are smaller than a given, large threshold, is described by the prime number theorem, but no efficient is known. Dirichlet's theorem on arithmetic progressions, in its basic form, asserts that linear polynomials

is finite. Because of Brun's theorem, it is not possible to use Euler's method to solve the twin prime conjecture, that there exist infinitely many twin primes.^{[75]}

An arithmetic progression is a finite or infinite sequence of numbers such that consecutive numbers in the sequence all have the same difference.^{[81]} This difference is called the modulus of the progression.^{[82]} For example,

is an infinite arithmetic progression with modulus 9. In an arithmetic progression, all the numbers have the same remainder when divided by the modulus; in this example, the remainder is 3. Because both the modulus 9 and the remainder 3 are multiples of 3, so is every element in the sequence. Therefore, this progression contains only one prime number, 3 itself. In general, the infinite progression

The Green–Tao theorem shows that there are arbitrarily long finite arithmetic progressions consisting only of primes.^{[35]}^{[84]}

The Ulam spiral arranges the natural numbers in a two-dimensional grid, spiraling in concentric squares surrounding the origin with the prime numbers highlighted. Visually, the primes appear to cluster on certain diagonals and not others, suggesting that some quadratic polynomials take prime values more often than others.^{[88]}

In an arbitrary ring, all prime elements are irreducible. The converse does not hold in general, but does hold for unique factorization domains.^{[108]}

The spectrum of a ring is a geometric space whose points are the prime ideals of the ring.^{[112]} Arithmetic geometry also benefits from this notion, and many concepts exist in both geometry and number theory. For example, factorization or ramification of prime ideals when lifted to an extension field, a basic problem of algebraic number theory, bears some resemblance with ramification in geometry. These concepts can even assist with in number-theoretic questions solely concerned with integers. For example, prime ideals in the ring of integers of quadratic number fields can be used in proving quadratic reciprocity, a statement that concerns the existence of square roots modulo integer prime numbers.^{[113]}
Early attempts to prove Fermat's Last Theorem led to Kummer's introduction of regular primes, integer prime numbers connected with the failure of unique factorization in the cyclotomic integers.^{[114]}
The question of how many integer prime numbers factor into a product of multiple prime ideals in an algebraic number field is addressed by Chebotarev's density theorem, which (when applied to the cyclotomic integers) has Dirichlet's theorem on primes in arithmetic progressions as a special case.^{[115]}

For a long time, number theory in general, and the study of prime numbers in particular, was seen as the canonical example of pure mathematics, with no applications outside of mathematics^{[b]} other than the use of prime numbered gear teeth to distribute wear evenly.^{[117]} In particular, number theorists such as British mathematician G. H. Hardy prided themselves on doing work that had absolutely no military significance.^{[118]}

This vision of the purity of number theory was shattered in the 1970s, when it was publicly announced that prime numbers could be used as the basis for the creation of public-key cryptography algorithms.^{[32]}
These applications have led to significant study of algorithms for computing with prime numbers, and in particular of primality testing, methods for determining whether a given number is prime.
The most basic primality testing routine, trial division, is too slow to be useful for large numbers. One group of modern primality tests is applicable to arbitrary numbers, while more efficient tests are available for numbers of special types. Most primality tests only tell whether their argument is prime or not. Routines that also provide a prime factor of composite arguments (or all of its prime factors) are called factorization algorithms.
Prime numbers are also used in computing for checksums, hash tables, and pseudorandom number generators.

Although this method is simple to describe, it is impractical for testing the primality of large integers, because the number of tests that it performs grows exponentially as a function of the number of digits of these integers.^{[120]} However, trial division is still used, with a smaller limit than the square root on the divisor size, to quickly discover composite numbers with small factors, before using more complicated methods on the numbers that pass this filter.^{[121]}

Before computers, mathematical tables listing all of the primes or prime factorizations up to a given limit were commonly printed.^{[122]} The oldest method for generating a list of primes is called the sieve of Eratosthenes.^{[123]} The animation shows an optimized variant of this method.^{[124]}
Another more asymptotically efficient sieving method for the same problem is the sieve of Atkin.^{[125]} In advanced mathematics, sieve theory applies similar methods to other problems.^{[126]}

In contrast, some other algorithms guarantee that their answer will always be correct: primes will always be determined to be prime and composites will always be determined to be composite.
For instance, this is true of trial division.
The algorithms with guaranteed-correct output include both deterministic (non-random) algorithms, such as the AKS primality test,^{[130]}
and randomized Las Vegas algorithms where the random choices made by the algorithm do not affect its final answer, such as some variations of elliptic curve primality proving.^{[127]}
When the elliptic curve method concludes that a number is prime, it provides primality certificate that can be verified quickly.^{[131]}
The elliptic curve primality test is the fastest in practice of the guaranteed-correct primality tests, but its runtime analysis is based on heuristic arguments rather than rigorous proofs. The AKS primality test has mathematically proven time complexity, but is slower than elliptic curve primality proving in practice.^{[132]} These methods can be used to generate large random prime numbers, by generating and testing random numbers until finding one that is prime;
when doing this, a faster probabilistic test can quickly eliminate most composite numbers before a guaranteed-correct algorithm is used to verify that the remaining numbers are prime.^{[d]}

In addition to the aforementioned tests that apply to any natural number, some numbers of a special form can be tested for primality more quickly.
For example, the Lucas–Lehmer primality test can determine whether a Mersenne number (one less than a power of two) is prime, deterministically,
in the same time as a single iteration of the Miller–Rabin test.^{[137]} This is why since 1992 (as of December 2018) the largest *known* prime has always been a Mersenne prime.^{[138]}
It is conjectured that there are infinitely many Mersenne primes.^{[139]}

The following table gives the largest known primes of various types. Some of these primes have been found using distributed computing. In 2009, the Great Internet Mersenne Prime Search project was awarded a US$100,000 prize for first discovering a prime with at least 10 million digits.^{[140]} The Electronic Frontier Foundation also offers $150,000 and $250,000 for primes with at least 100 million digits and 1 billion digits, respectively.^{[141]}

Shor's algorithm can factor any integer in a polynomial number of steps on a quantum computer.^{[152]} However, current technology can only run this algorithm for very small numbers. As of October 2012 the largest number that has been factored by a quantum computer running Shor's algorithm is 21.^{[153]}

Prime numbers are frequently used for hash tables. For instance the original method of Carter and Wegman for universal hashing was based on computing hash functions by choosing random linear functions modulo large prime numbers. Carter and Wegman generalized this method to by using higher-degree polynomials, again modulo large primes.^{[156]} As well as in the hash function, prime numbers are used for the hash table size in quadratic probing based hash tables to ensure that the probe sequence covers the whole table.^{[157]}

Prime numbers are of central importance to number theory but also have many applications to other areas within mathematics, including abstract algebra and elementary geometry. For example, it is possible to place prime numbers of points in a two-dimensional grid so that no three are in a line, or so that every triangle formed by three of the points has large area.^{[162]} Another example is Eisenstein's criterion, a test for whether a polynomial is irreducible based on divisibility of its coefficients by a prime number and its square.^{[163]}

The concept of a prime number is so important that it has been generalized in different ways in various branches of mathematics. Generally, "prime" indicates minimality or indecomposability, in an appropriate sense. For example, the prime field of a given field is its smallest subfield that contains both 0 and 1. It is either the field of rational numbers or a finite field with a prime number of elements, whence the name.^{[164]} Often a second, additional meaning is intended by using the word prime, namely that any object can be, essentially uniquely, decomposed into its prime components. For example, in knot theory, a prime knot is a knot that is indecomposable in the sense that it cannot be written as the connected sum of two nontrivial knots. Any knot can be uniquely expressed as a connected sum of prime knots.^{[165]} The prime decomposition of 3-manifolds is another example of this type.^{[166]}

Beyond mathematics and computing, prime numbers have potential connections to quantum mechanics, and have been used metaphorically in the arts and literature. They have also been used in evolutionary biology to explain the life cycles of cicadas.

Beginning with the work of Hugh Montgomery and Freeman Dyson in the 1970s, mathematicians and physicists have speculated that the zeros of the Riemann zeta function are connected to the energy levels of quantum systems.^{[172]}^{[173]} Prime numbers are also significant in quantum information science, thanks to mathematical structures such as mutually unbiased bases and .^{[174]}^{[175]}

The evolutionary strategy used by cicadas of the genus *Magicicada* makes use of prime numbers.^{[176]} These insects spend most of their lives as grubs underground. They only pupate and then emerge from their burrows after 7, 13 or 17 years, at which point they fly about, breed, and then die after a few weeks at most. Biologists theorize that these prime-numbered breeding cycle lengths have evolved in order to prevent predators from synchronizing with these cycles.^{[177]}^{[178]}
In contrast, the multi-year periods between flowering in bamboo plants are hypothesized to be smooth numbers, having only small prime numbers in their factorizations.^{[179]}

Prime numbers have influenced many artists and writers.
The French composer Olivier Messiaen used prime numbers to create ametrical music through "natural phenomena". In works such as *La Nativité du Seigneur* (1935) and *Quatre études de rythme* (1949–50), he simultaneously employs motifs with lengths given by different prime numbers to create unpredictable rhythms: the primes 41, 43, 47 and 53 appear in the third étude, "Neumes rythmiques". According to Messiaen this way of composing was "inspired by the movements of nature, movements of free and unequal durations".^{[180]}

In his science fiction novel *Contact*, scientist Carl Sagan suggested that prime factorization could be used as a means of establishing two-dimensional image planes in communications with aliens, an idea that he had first developed informally with American astronomer Frank Drake in 1975.^{[181]} In the novel *The Curious Incident of the Dog in the Night-Time* by Mark Haddon, the narrator arranges the sections of the story by consecutive prime numbers as a way to convey the mental state of its main character, a mathematically gifted teen with Asperger syndrome.^{[182]} Prime numbers are used as a metaphor for loneliness and isolation in the Paolo Giordano novel *The Solitude of Prime Numbers*, in which they are portrayed as "outsiders" among integers.^{[183]}