GMLscripts.com

lcm

Returns the least common multiple of the given integers.

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

Wikipedia:

Multiples of 4 are:

Multiples of 6 are:

Common multiples of 4 and 6 are the numbers that are in both lists:

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