# lcm

Returns the least common multiple of the given integers.

$$\operatorname{lcm}(a,b)=\frac{|ab|}{\text{gcd}(a,b)}$$

Wikipedia:

$$\operatorname{lcm}(4,6)$$

Multiples of 4 are: $$4,8,12,16,20,24,28,32,36,40,44,48,52,56,60,64,68,72,76,...$$

Multiples of 6 are: $$6,12,18,24,30,36,42,48,54,60,66,72,...$$

Common multiples of 4 and 6 are the numbers that are in both lists: $$12,24,36,48,60,...$$

In this list, the smallest number is 12. Hence the least common multiple is 12.

lcm(a, b)
Returns the least common multiple of the given integers.
COPY/// @func   lcm(a, b)
///
/// @desc   Returns the least common multiple of the given integers.
///
/// @param  {real}      a           positive integer
/// @param  {real}      b           positive integer
///
/// @return {real}      least common multiple
///
/// GMLscripts.com/license

function lcm(a, b)
{
var c = a * b;
while (b != 0) {
var r = a mod b;
a = b;
b = r;
}
return abs(c / a);
}


Contributors: xot

GitHub: View · Commits · Blame · Raw