Algorithm for Computing the LCM
22.19
Diposting oleh Melany Christy
The applet below illustrates an algorithm for finding the Least Common Multiple (LCM) of a number of integers.
Let there be a finite sequence of positive integers
xk(m+1) | = xk(m), | k ≠ k0 | |
xk0(m+1) | = xk0(m) + xk0. |
In other words, the least element is increased by the corresponding x whereas the rest of the elements pass from X(m) to X(m+1) unchanged.
The algorithm stops when all elements in sequence X(m) are equal. Their common value L is exactly LCM(X).
(In the applet the numbers x1, x2, ..., xn that appear at the top row are modifiable by clicking left or right off their vertical center line. Press button Compute to see the algorithm running. The blue numbers the ones that have been modified at one of the steps.)
Posting Komentar