# Fermat number

In mathematics, a **Fermat number**, named after Pierre de Fermat, who first studied them, is a positive integer of the form

If 2^{k} + 1 is prime and *k* > 0, then *k* must be a power of 2, so 2^{k} + 1 is a Fermat number; such primes are called **Fermat primes**. As of 2021, the only known Fermat primes are *F*_{0} = 3, *F*_{1} = 5, *F*_{2} = 17, *F*_{3} = 257, and *F*_{4} = 65537 (sequence in the OEIS); heuristics suggest that there are no more.

for *n* ≥ 2. Each of these relations can be proved by mathematical induction. From the second equation, we can deduce **Goldbach's theorem** (named after Christian Goldbach): no two Fermat numbers share a common integer factor greater than 1. To see this, suppose that 0 ≤ *i* < *j* and *F*_{i} and *F*_{j} have a common factor *a* > 1. Then *a* divides both

Fermat numbers and Fermat primes were first studied by Pierre de Fermat, who conjectured that all Fermat numbers are prime. Indeed, the first five Fermat numbers *F*_{0}, ..., *F*_{4} are easily shown to be prime. Fermat's conjecture was refuted by Leonhard Euler in 1732 when he showed that

Euler proved that every factor of *F*_{n} must have the form *k* 2^{n+1} + 1 (later improved to *k* 2^{n+2} + 1 by Lucas).

That 641 is a factor of *F*_{5} can be deduced from the equalities 641 = 2^{7} × 5 + 1 and 641 = 2^{4} + 5^{4}. It follows from the first equality that 2^{7} × 5 ≡ −1 (mod 641) and therefore (raising to the fourth power) that 2^{28} × 5^{4} ≡ 1 (mod 641). On the other hand, the second equality implies that 5^{4} ≡ −2^{4} (mod 641). These congruences imply that 2^{32} ≡ −1 (mod 641).

Fermat was probably aware of the form of the factors later proved by Euler, so it seems curious that he failed to follow through on the straightforward calculation to find the factor.^{[1]} One common explanation is that Fermat made a computational mistake.

There are no other known Fermat primes *F*_{n} with *n* > 4, but little is known about Fermat numbers for large *n*.^{[2]} In fact, each of the following is an open problem:

As of 2014, it is known that *F*_{n} is composite for 5 ≤ *n* ≤ 32, although of these, complete factorizations of *F*_{n} are known only for 0 ≤ *n* ≤ 11, and there are no known prime factors for *n* = 20 and *n* = 24.^{[4]} The largest Fermat number known to be composite is *F*_{18233954}, and its prime factor 7 × 2^{18233956} + 1, a megaprime, was discovered in October 2020.

The prime number theorem implies that a random integer in a suitable interval around *N* is prime with probability 1 / ln *N*. If one uses the heuristic that a Fermat number is prime with the same probability as a random integer of its size, and that *F*_{5}, ..., *F*_{32} are composite, then the expected number of Fermat primes beyond *F*_{4} (or equivalently, beyond *F*_{32}) should be

One may interpret this number as an upper bound for the probability that a Fermat prime beyond *F*_{4} exists.

This argument is not a rigorous proof. For one thing, it assumes that Fermat numbers behave "randomly", but the factors of Fermat numbers have special properties. Boklan and Conway published a more precise analysis suggesting that the probability that there is another Fermat prime is less than one in a billion.^{[5]}

There are some tests for numbers of the form *k* 2^{m} + 1, such as factors of Fermat numbers, for primality.

If *N* = *F*_{n} > 3, then the above Jacobi symbol is always equal to −1 for *a* = 3, and this special case of Proth's theorem is known as Pépin's test. Although Pépin's test and Proth's theorem have been implemented on computers to prove the compositeness of some Fermat numbers, neither test gives a specific nontrivial factor. In fact, no specific prime factors are known for *n* = 20 and 24.

As of 2018, only *F*_{0} to *F*_{11} have been completely factored.^{[4]} The distributed computing project Fermat Search is searching for new factors of Fermat numbers.^{[7]} The set of all Fermat factors is A050922 (or, sorted, A023394) in OEIS.

The following factors of Fermat numbers were known before 1950 (since then, digital computers have helped find more factors):

As of January 2021, 356 prime factors of Fermat numbers are known, and 312 Fermat numbers are known to be composite.^{[4]} Several new Fermat factors are found each year.^{[8]}

Like composite numbers of the form 2^{p} − 1, every composite Fermat number is a strong pseudoprime to base 2. This is because all strong pseudoprimes to base 2 are also Fermat pseudoprimes - i.e.

In fact, it can be seen directly that 2 is a quadratic residue modulo *p*, since

Since an odd power of 2 is a quadratic residue modulo *p*, so is 2 itself.

A Fermat number cannot be a perfect number or part of a pair of amicable numbers. (Luca 2000)

The series of reciprocals of all prime divisors of Fermat numbers is convergent. (Křížek, Luca & Somer 2002)

If *n*^{n} + 1 is prime, there exists an integer *m* such that *n* = 2^{2m}. The equation
*n*^{n} + 1 = *F*_{(2m+m)}
holds in that case.^{[10]}^{[11]}

Carl Friedrich Gauss developed the theory of Gaussian periods in his *Disquisitiones Arithmeticae* and formulated a sufficient condition for the constructibility of regular polygons. Gauss stated that this condition was also necessary, but never published a proof. Pierre Wantzel gave a full proof of necessity in 1837. The result is known as the **Gauss–Wantzel theorem**:

A positive integer *n* is of the above form if and only if its totient φ(*n*) is a power of 2.

Fermat primes are particularly useful in generating pseudo-random sequences of numbers in the range 1 ... *N*, where *N* is a power of 2. The most common method used is to take any seed value between 1 and *P* − 1, where *P* is a Fermat prime. Now multiply this by a number *A*, which is greater than the square root of *P* and is a primitive root modulo *P* (i.e., it is not a quadratic residue). Then take the result modulo *P*. The result is the new value for the RNG.

This is useful in computer science since most data structures have members with 2^{X} possible values. For example, a byte has 256 (2^{8}) possible values (0–255). Therefore, to fill a byte or bytes with random values a random number generator which produces values 1–256 can be used, the byte taking the output value −1. Very large Fermat primes are of particular interest in data encryption for this reason. This method produces only pseudorandom values as, after *P* − 1 repetitions, the sequence repeats. A poorly chosen multiplier can result in the sequence repeating sooner than *P* − 1.

An example of a probable prime of this form is 124^{65536} + 57^{65536} (found by Valeryi Kuryshev).^{[12]}

If we require *n* > 0, then Landau's fourth problem asks if there are infinitely many generalized Fermat primes *F _{n}*(

*a*).

Because of the ease of proving their primality, generalized Fermat primes have become in recent years a topic for research within the field of number theory. Many of the largest known primes today are generalized Fermat primes.

(See ^{[13]}^{[14]} for more information (even bases up to 1000), also see ^{[15]} for odd bases)

The following is a list of the 5 largest known generalized Fermat primes.^{[16]} They are all megaprimes. The whole top-5 is discovered by participants in the PrimeGrid project.