WOLFRAM|DEMONSTRATIONS PROJECT

LCM, GCD, and MOD

​
first entry
18
second entry
7
LCM[
18
,
7
] = LCM[
1
2
·
2
3
,
1
7
] =
1
2
·
2
3
·
1
7
=
126
GCD[
18
,
7
] = GCD[
1
2
·
2
3
,
1
7
] =
1
1
=
1
18
≡
4
( mod
7
)
since
18
=
2
·
7
+
4
This Demonstration illustrates the concepts of the least common multiple (LCM) and the greatest common divisor (GCD). It depends on explicit factoring; the factorization is used to show the GCD and LCM. The Euclidean algorithm finds the GCD much more efficiently because it does not rely on factoring. In any case, you can find the LCM of
a
and
b
from the GCD:
LCM(a,b)=ab/GCD(a,b)
.
You can also see how to perform some basic modular arithmetic.