KEVOS
ArticlesServicesCase studiesAboutContact
ArticlesServicesCase studiesAboutContact
← ArticlesLehmer's Accelerated GCD ComputationEngineering · Engineering MathematicsLesson 715/884← PrevNext →
ArticlePublished 7 Aug 20262 min readBy Kevin JoginLehmer GCDaccelerationsingle precisionquotient sequence
On this page

Ask about this page

KEVOS AILehmer's Accelerated GCD Computation

KEVOS knowledge first · trusted web sources when needed

Euclidean Algorithms and Congruences

Lehmer's Accelerated GCD Computation

Lehmer's method: running many GCD steps on single-precision leading digits before touching the full multiprecision operands.

Engineering / MathematicsEuclidean Algorithms and Congruences2 min readKV-MATH-0514

Lehmer's observation is that the sequence of quotients in the Euclidean algorithm usually depends only on the leading digits of the operands. Many steps can therefore be simulated in single precision and applied to the full operands in one batch.

The idea

Take the leading limbs of both operands. Run the Euclidean algorithm on those single-precision values, accumulating the transformation as a two-by-two integer matrix, and stop as soon as the quotient computed from the leading digits might differ from the true quotient.

(a, b) -> (A a + B b, C a + D b)The matrix entries stay small; the multiprecision update happens once for many steps.

Lehmer's accelerated GCD

  1. ExtractTake the top limb of the larger operand and the corresponding limb of the smaller.
  2. SimulateRun Euclidean steps on the single-precision pair, updating the transformation matrix.
  3. GuardStop when the quotient from the leading digits is no longer provably correct — a bound test on the matrix entries.
  4. ApplyApply the accumulated matrix to the full operands with multiprecision arithmetic.
  5. RepeatContinue until the operands fit in single precision.

Why it wins

Key point

The multiprecision work per Euclidean step is what costs. Lehmer replaces one multiprecision division per step with one multiprecision matrix application per batch of steps, and the batches are typically tens of steps long.

The guard condition

Pitfall

The guard is the whole correctness argument. Simulated quotients are only valid while the discarded low-order digits cannot change them. Implementations that loosen this test produce wrong GCDs on rare inputs, which is precisely the kind of bug that survives casual testing.

Relationship to other methods

GCD methods compared
MethodApproachComplexity
ClassicalOne division per stepO(n^2) bit operations
BinaryShifts and subtractionsO(n^2), smaller constant
LehmerBatched single-precision simulationO(n^2), much smaller constant
Half-GCDDivide and conquerO(M(n) log n)

Lehmer's method does not improve the asymptotic exponent — it reduces the constant substantially, which is why it remains the workhorse in the range where most computation actually happens. The same batching idea extends to the extended algorithm; see the extended algorithm.

Source. Henri Cohen, A Course in Computational Algebraic Number Theory, Springer GTM 138 — 1.3.1. 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.

Related pages

  • The Euclidean Algorithm: Classical and Binary Variants
  • The Extended Euclidean Algorithm and Bezout Coefficients

Continue learning

The Euclidean Algorithm: Classical and Binary VariantsArticle · Engineering MathematicsNEXT LESSON →The Extended Euclidean Algorithm and Bezout CoefficientsArticle · Engineering MathematicsInteger Square Root and Perfect Power DetectionArticle · Engineering MathematicsChinese Remainder Theorem AlgorithmsArticle · Engineering Mathematics
KEVOS · Engineering, manufacturing and project improvement
ArticlesServicesCase studiesAboutContact
© 2026 KEVOS®