2019-12-24 17:03:42 +01:00
|
|
|
# Least Common Multiple
|
|
|
|
|
|
|
|
The least common multiple of two integers a and b, is the
|
|
|
|
smallest positive integer that is divisible by both a and b.
|
|
|
|
|
|
|
|
This implements a word to find this in RETRO.
|
|
|
|
|
|
|
|
It uses a formula that reduces the problem to computing the
|
|
|
|
greatest common divisor (gcd), as in:
|
|
|
|
|
|
|
|
lcm(a,b) = |a*b| / gcd(a,b)
|
2017-10-16 18:09:39 +02:00
|
|
|
|
2018-04-25 18:57:28 +02:00
|
|
|
~~~
|
2017-10-16 18:09:39 +02:00
|
|
|
:gcd (ab-n)
|
|
|
|
[ tuck mod dup ] while drop ;
|
|
|
|
|
|
|
|
:lcm (ab-n)
|
|
|
|
dup-pair gcd [ * ] dip / ;
|
2018-04-25 18:57:28 +02:00
|
|
|
~~~
|