← LibraryN+1 Tests and the Lucas-Lehmer TestEngineering · Engineering MathematicsLesson 457/488← PrevNext →
ArticlePublished 7 Aug 2026Updated 8 Aug 20262 min readBy Kevin JoginN+1 testLucas LehmerMersenne primeLucas sequence

Classical Primality and Factoring

N+1 Tests and the Lucas-Lehmer Test

Primality tests using the factorisation of one more than the candidate, and the Lucas-Lehmer test for Mersenne numbers.

Engineering / MathematicsClassical Primality and Factoring2 min readKV-MATH-0651

The N+1 tests are the Lucas-sequence duals of Pocklington-Lehmer, using the factorisation of one more than the candidate. The Lucas-Lehmer test for Mersenne numbers is the celebrated special case.

The dual criterion

Where the N-1 test works in the multiplicative group modulo the candidate, the N+1 test works in the quadratic extension, where the relevant group has order one more than the candidate.

Combined tests

When neither one less nor one more can be factored sufficiently, combined criteria use partial factorisations of both. These extend the practical range considerably.

Choosing among classical proving methods
Available factorisationMethod
One less, past the square rootPocklington-Lehmer
One more, past the square rootN+1 test
Partial of bothCombined criteria, e.g. Brillhart-Lehmer-Selfridge
NeitherRequires a modern general method

Mersenne numbers

A Mersenne number is one less than a power of two. One more than it is a power of two, which is completely factored by inspection, so the N+1 machinery applies with no factoring work at all.

M_p = 2^p - 1, so M_p + 1 = 2^pCompletely factored, which is exactly what the N+1 test needs.

The Lucas-Lehmer test

For Mersenne numbers with prime exponent, the test reduces to a single recurrence: iterate a squaring map a fixed number of times and check whether the result vanishes.

The Lucas-Lehmer test

  1. StartBegin with the value four.
  2. IterateReplace by its square minus two, reduced modulo the Mersenne number.
  3. RepeatTwo fewer times than the exponent.
  4. TestThe number is prime exactly when the final value is zero.

Why Mersenne numbers are efficient

Other special forms

Fermat numbers, Proth numbers and generalised Fermat numbers all admit similar specialised tests based on the structure of one more or one less than the candidate. Each rests on the same principle: a known factorisation on one side.

Source. Henri Cohen, A Course in Computational Algebraic Number Theory, Springer GTM 138 — 8.4. Structural reference unverified: the source file was not available during authoring; chapter and section numbers are taken from the published edition and have not been checked against a physical copy.

Continue learning

The Pocklington-Lehmer N-1 Primality TestArticle · Engineering MathematicsNEXT LESSON →Trial Division and Lehman's MethodArticle · Engineering MathematicsThe Baillie-PSW Compositeness TestArticle · Engineering MathematicsThe Pollard Rho Factoring MethodArticle · Engineering Mathematics