Lucas-Lehmer Test — Definition, Formula & Examples
The Lucas-Lehmer test is a primality test that determines whether a Mersenne number is prime. It works by computing a specific recursive sequence modulo and checking whether the final term is zero.
For an odd prime , define the sequence and for . The Mersenne number is prime if and only if .
Key Formula
Where:
- = The k-th term of the Lucas-Lehmer sequence
- = The Mersenne number $2^p - 1$
- = An odd prime exponent
How It Works
Start by setting . At each step, square the current value, subtract 2, and reduce the result modulo . Repeat this times total, producing . If the final value is exactly 0 modulo , then is prime. Otherwise, is composite. The test only applies when itself is an odd prime, since is always composite when is composite.
Worked Example
Problem: Use the Lucas-Lehmer test to determine whether is prime.
Setup: Since , we need to compute iterations of the sequence, checking whether .
Step 1: Start with . Compute :
Step 2: Compute :
Step 3: Compute :
Step 4: Compute :
Step 5: Compute :
Answer: Since , the Mersenne number is prime.
Why It Matters
The Lucas-Lehmer test is the method behind every record-breaking prime discovery by the Great Internet Mersenne Prime Search (GIMPS). Its efficiency — requiring only modular squarings — makes it feasible to test numbers with millions of digits, far beyond the reach of general-purpose primality tests.
Common Mistakes
Mistake: Applying the test to arbitrary integers, not just Mersenne numbers of the form with an odd prime.
Correction: The Lucas-Lehmer test is specifically designed for Mersenne numbers. For general integers, use other primality tests such as Miller-Rabin or AKS.
