In mathematics, the **Lucas-Lehmer test** is a special test to see if a given Mersenne number *M*_{p} is prime or not. The test was originally developed by Edouard Lucas in 1878 and subsequently improved by Derrick Henry Lehmer in the 1930s, and works as follows:

Define a sequence (*s*_{k}) by setting *s*_{0} = 4 and *s*_{i} = *s*²_{i − 1} − 2; the first few terms of this sequence are 4, 14, 194, 37634, ... (Sloane's A003010). Then, a Mersenne number *M*_{p} is prime iff 0 = *s*_{p − 2} mod *M*_{p}; otherwise, *M*_{p} is composite, and *s*_{p − 2} mod *M*_{p} is called the **Lucas-Lehmer residue of p**.