The Lucas–Lehmer test (LLT) is a primality test for Mersenne numbers.
The Lucas–Lehmer test works as follows. Let $M_p = 2^p − 1$ be the Mersenne number to test with $p$ an odd prime. The primality of $p$ can be efficiently checked with a simple algorithm like trial division since $p$ is exponentially smaller than $M_p$. Define a sequence $ \{ s _ i \} $ for all $ i \ge 0 $ by
$$ s _ i = \begin{cases} 4 & \text{if } i = 0 \text ; \\\\ s _ { i - 1 } ^ 2 - 2 & \text{otherwise.} \end{cases} $$
The first few terms of this sequence are $4$, $14$, $194$, $37634$, $\dots$. Then $M_p$ is prime if and only if
$$ s _ { p - 2 } \equiv 0 \pmod { M _ p } \text . $$
The number $ s _ { p - 2 } mod M _ p $ is called the Lucas–Lehmer residue of $p$. (Some authors equivalently set $ s _ 1 = 4 $ and test $ s _ { p - 1 } \mod M _ p $).
Starting values $ s _ 0 $ other than $ 4 $ are possible, for instance $ 10 $, $ 52 $, and others. The Lucas-Lehmer residue calculated with these alternative starting values will still be zero if $ M _ p $ is a Mersenne prime. However, the terms of the sequence will be different and a non-zero Lucas-Lehmer residue for non-prime $ M _ p $ will have a different numerical value from the non-zero value calculated when $ s _ 0 = 4 $.
It is also possible to use the starting value $ ( 2 \mod M _ p ) ( 3 \mod M _ p ) ^ { - 1 } $, usually denoted by $ \frac 2 3 $ for short. This starting value equals $ \frac { 2 ^ p + 1 } 3 $, the Wagstaff number with exponent $ p $.
Starting values like $ 4 $, $ 10 $, and $ \frac 2 3 $ are universal, that is, they are valid for all (or nearly all) $ p $. There are infinitely many additional universal starting values. However, some other starting values are only valid for a subset of all possible $ p $, for example $ s _ 0 = 3 $ can be used if $ p = 3 \pmod 4 $. This starting value was often used where suitable in the era of hand computation, including by Lucas in proving $ M _ { 127 } $ prime. The first few terms of the sequence are $ 3 $, $ 7 $, $ 47 $, $ \dots $.
Source: Wikipedia