title: Pépin's test
text: # Pépin's test
  
  In mathematics, Pépin's test is a primality test, which can be used to determine whether a Fermat number is prime. It is a variant of Proth's test. The test is named for a French mathematician, Théophile Pépin.
  
  ## Description of the test
  
  Let $F_{n}=2^{2^{n}}+1$ be the nth Fermat number. Pépin's test states that for n > 0,
  
      $F_{n}$ is prime if and only if $3^{(F_{n}-1)/2}\equiv -1{\pmod {F_{n}}}.$
  
  The expression $3^{(F_{n}-1)/2}$ can be evaluated modulo $F_{n}$ by repeated squaring. This makes the test a fast polynomial-time algorithm. However, Fermat numbers grow so rapidly that only a handful of Fermat numbers can be tested in a reasonable amount of time and space.
  
  Other bases may be used in place of 3. These bases are:
  
      3, 5, 6, 7, 10, 12, 14, 20, 24, 27, 28, 39, 40, 41, 45, 48, 51, 54, 56, 63, 65, 75, 78, 80, 82, 85, 90, 91, 96, 102, 105, 108, 112, 119, 125, 126, 130, 147, 150, 156, 160, ... (sequence A129802 in the OEIS).
  
  The primes in the above sequence are called Elite primes, they are:
  
      3, 5, 7, 41, 15361, 23041, 26881, 61441, 87041, 163841, 544001, 604801, 6684673, 14172161, 159318017, 446960641, 1151139841, 3208642561, 38126223361, 108905103361, 171727482881, 318093312001, 443069456129, 912680550401, ... (sequence A102742 in the OEIS)
  
  For integer b > 1, base b may be used if and only if only a finite number of Fermat numbers $F_n$ satisfies that $\left({\frac {b}{F_{n}}}\right)=1$, where $\left({\frac {b}{F_{n}}}\right)$ is the Jacobi symbol.
  
  In fact, Pépin's test is the same as the Euler-Jacobi test for Fermat numbers, since the Jacobi symbol $\left({\frac {b}{F_{n}}}\right)$ is −1, i.e. there are no Fermat numbers which are Euler-Jacobi pseudoprimes to these bases listed above.
  
  ## Proof of correctness
  
  Sufficiency: assume that the congruence
  
      $3^{(F_{n}-1)/2}\equiv -1{\pmod {F_{n}}}$
  
  holds. Then $3^{F_{n}-1}\equiv 1{\pmod {F_{n}}}$, thus the multiplicative order of 3 modulo $F_{n}$ divides $F_{n}-1=2^{2^{n}}$, which is a power of two. On the other hand, the order does not divide $(F_{n}-1)/2$, and therefore it must be equal to $F_{n}-1$. In particular, there are at least $F_{n}-1$ numbers below $F_{n}$ coprime to $F_{n}$, and this can happen only if $F_{n}$ is prime.
  
  Necessity: assume that $F_{n}$ is prime. By Euler's criterion,
  
      $3^{(F_{n}-1)/2}\equiv \left({\frac {3}{F_{n}}}\right){\pmod {F_{n}}}$,
  
  where $\left({\frac {3}{F_{n}}}\right)$ is the Legendre symbol. By repeated squaring, we find that $2^{2^{n}}\equiv 1{\pmod {3}}$, thus $F_{n}\equiv 2{\pmod {3}}$, and $\left({\frac {F_{n}}{3}}\right)=-1$. As $F_{n}\equiv 1{\pmod {4}}$, we conclude $\left({\frac {3}{F_{n}}}\right)=-1$ from the law of quadratic reciprocity.
  
  ## Historical Pépin tests
  
  Because of the sparsity of the Fermat numbers, the Pépin test has only been run eight times (on Fermat numbers whose primality statuses were not already known). Mayer, Papadopoulos and Crandall speculate that in fact, because of the size of the still undetermined Fermat numbers, it will take considerable advances in technology before any more Pépin tests can be run in a reasonable amount of time. As of 2023 the smallest untested Fermat number with no known prime factor is $F_{33}$ which has 2,585,827,973 digits.
  
  | Year | Provers | Fermat number | Pépin test result | Factor found later? |
  | - | - | - | - | - |
  | 1905 | Morehead & Western | $F_{7}$ | composite | Yes (1970) |
  | 1909 | Morehead & Western | $F_{8}$ | composite | Yes (1980) |
  | 1952 | Robinson | $F_{10}$ | composite | Yes (1953) |
  | 1960 | Paxson | $F_{13}$ | composite | Yes (1974) |
  | 1961 | Selfridge & Hurwitz | $F_{14}$ | composite | Yes (2010) |
  | 1987 | Buell & Young | $F_{20}$ | composite | No |
  | 1993 | Crandall, Doenias, Norrie & Young | $F_{22}$ | composite | Yes (2010) |
  | 1999 | Mayer, Papadopoulos & Crandall | $F_{24}$ | composite | No |
  