In mathematics, the Lucas-Lehmer test is a special test to see if a given Mersenne number Mp 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 (sk) by setting s0 = 4 and si = s²i − 1 − 2; the first few terms of this sequence are 4, 14, 194, 37634, ... (Sloane's A003010). Then, a Mersenne number Mp is prime iff 0 = sp − 2 mod Mp; otherwise, Mp is composite, and sp − 2 mod Mp is called the Lucas-Lehmer residue of p.