GO-V.ORG
As seen in

Lehmer's GCD algorithm

Lehmer's GCD algorithm, named after D. H. Lehmer, is a fast GCD algorithm for multiple-precision arithmetic, which improves on the simpler Euclidean algorithm by doing most operations using only the leading digits of the values. "Digit" here is not necessarily a decimal digit; the algorithm is often used with integers represented using a base β such as β = 1000 or β = 2 32. Source: e01 Encyclopedia. Licence: CC BY-SA 4.0.

Lehmer's GCD algorithm, named after D. H. Lehmer, is a fast GCD algorithm for multiple-precision arithmetic, which improves on the simpler Euclidean algorithm by doing most operations using only the leading digits of the values. "Digit" here is not necessarily a decimal digit; the algorithm is often used with integers represented using a base β such as β = 1000 or β = 2 32 . If b contains only one digit (in the chosen base, say β = 1000 or β = 2 32 ), use some other method, such as the Euclidean algorithm, to obtain the result. If a and b differ in the length of digits, reduce a modulo b and exchange them as in the standard Euclidean algorithm. Repeat until the two are of the same length m. Outer loop: Iterate until one of a or b is zero: Decrease m by one. Let x be the leading (most significant) digit in a, x = a div β m and y the leading digit in b, y = b div β m . Initialize a 2 by 3 matrix \textstyle \begin{bmatrix} A & B & x\\ C & D & y \end{bmatrix} to an extended identity matrix \textstyle \begin{bmatrix} 1 & 0 & x \\ 0 & 1 & y\end{bmatrix}, and perform the Euclidean algorithm simultaneously on the pairs (x + A, y + C) and (x + B, y + D), until the quotients differ. That is, iterate as an inner loop: Compute the quotients w 1 of the long divisions of (x + A) by (y + C) and w 2 of (x + B) by (y + D) respectively. If these are equal, they also equal w, the (not computed) quotient from the corresponding step of the ordinary Euclidean algorithm. If w 1 ≠ w 2 , then break out of the inner iteration. Else set w to w 1 (or w 2 ). Replace the current matrix \textstyle \begin{bmatrix} A & B & x \\ C & D & y \end{bmatrix} with the matrix product \textstyle \begin{bmatrix} 0 & 1 \\ 1 & -w \end{bmatrix} \cdot \begin{bmatrix} A & B & x \\ C & D & y \end{bmatrix} ==References== Kapil Paranjape, Lehmer's Algorithm

source: e01 Encyclopedia · licence: CC BY-SA 4.0 · page · source revision

Cite this

"Lehmer's GCD algorithm". 1780933332. e01 Encyclopedia. CC BY-SA 4.0. https://en.wikipedia.org/w/index.php?oldid=1358436605

JSON record · API collection · BibTeX · RIS · CSL-JSON · citation policy

Save to pass ·