Content deleted Content added
m →Algorithm: punctuation correction |
No edit summary |
||
(28 intermediate revisions by 19 users not shown) | |||
Line 1:
'''Lehmer's GCD algorithm''', named after [[Derrick Henry Lehmer]], is a fast [[greatest common divisor|GCD]] [[algorithm]], an improvement on the simpler but slower [[Euclidean algorithm]]. It is mainly used for big integers that have a representation as a string of digits relative to some chosen numeral system [[radix|base]], say ''β'' = 1000 or ''β'' = 2<sup>32</sup>.
== Algorithm ==
Say we want to obtain the GCD of the two integers ''a'' and ''b''. Let
* If ''b'' contains only one digit (in the chosen [[radix|base]], say
* If ''a'' and ''b'' differ in the length of digits, perform a division so that ''a'' and ''b'' are equal in length, with length equal to ''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'',
** Initialize a 2 by 3 [[matrix (mathematics)|matrix]]
*::<math>\textstyle \begin{bmatrix} A & B & x\\ C & D & y \end{bmatrix} </math> to an extended [[identity matrix]] <math>\textstyle \begin{bmatrix} 1 & 0 & x \\ 0 & 1 & y\end{bmatrix}, </math> *:and perform the euclidean algorithm simultaneously on the pairs *
*** If ''w''<sub>1</sub>
*** Replace the current matrix
**::<math>\textstyle \begin{bmatrix} A & B & x \\ C & D & y \end{bmatrix}</math>
*** If ''B'' = 0, we have reached a ''deadlock''; perform a normal step of the euclidean algorithm with ''a'' and ''b'', and recompute the matrix. ▼
**: with the matrix product
** Set ''a'' to ''aA'' + ''bB'' and ''b'' to ''Ca'' + ''Db'' (again simultaneously). This applies the steps of the euclidean algorithm that were performed on the leading digits in compressed form to the long integers ''a'' and ''b''. Restart the outer iteration.▼
**:: <math>\textstyle
\begin{bmatrix} 0 & 1 \\ 1 & -w \end{bmatrix}
\cdot
\begin{bmatrix} A & B & x \\ C & D & y \end{bmatrix}
= \begin{bmatrix} C & D &y \\ A - wC & B - wD & x-wy \end{bmatrix}
</math>
**:according to the matrix formulation of the extended euclidean algorithm.
***If ''B'' ≠ 0, go to the start of the inner loop.
▲
▲** Set ''a'' to ''aA'' + ''bB'' and ''b'' to ''Ca'' + ''Db'' (again simultaneously). This applies the steps of the euclidean algorithm that were performed on the leading digits in compressed form to the long integers ''a'' and ''b''.
==
<references/>
* Kapil Paranjape, [http://www.imsc.res.in/~kapil/crypto/notes/node11.html Lehmer's Algorithm]▼
▲* [[Kapil Hari Paranjape|Kapil Paranjape]], [http://www.imsc.res.in/~kapil/crypto/notes/node11.html Lehmer's Algorithm]
{{Number-theoretic algorithms}}
{{DEFAULTSORT:Lehmer's Gcd Algorithm}}
[[Category:Number theoretic algorithms]]
|