;Task:
Compute the &nbsp; least common multiple &nbsp; (LCM) &nbsp; of two integers.

Given &nbsp; ''m'' &nbsp; and &nbsp; ''n'', &nbsp; the least common multiple is the smallest positive integer that has both &nbsp; ''m'' &nbsp; and &nbsp; ''n'' &nbsp; as factors. 


;Example:
The least common multiple of &nbsp; '''12''' &nbsp; and &nbsp; '''18''' &nbsp; is &nbsp; '''36''', &nbsp; &nbsp; &nbsp; because:
:* &nbsp; '''12''' &nbsp; is a factor &nbsp; &nbsp; ('''12''' &times; '''3''' = '''36'''), &nbsp; &nbsp; and 
:* &nbsp; '''18''' &nbsp; is a factor &nbsp; &nbsp; ('''18''' &times; '''2''' = '''36'''), &nbsp; &nbsp; and 
:* &nbsp; there is no positive integer less than &nbsp; '''36''' &nbsp; that has both factors. 


As a special case, &nbsp; if either &nbsp; ''m'' &nbsp; or &nbsp; ''n'' &nbsp; is zero, &nbsp; then the least common multiple is zero.


One way to calculate the least common multiple is to iterate all the multiples of &nbsp; ''m'', &nbsp; until you find one that is also a multiple of &nbsp; ''n''.

If you already have &nbsp; ''gcd'' &nbsp; for [[greatest common divisor]], &nbsp; then this formula calculates &nbsp; ''lcm''.

<big>
:::: <math>\operatorname{lcm}(m, n) = \frac{|m \times n|}{\operatorname{gcd}(m, n)}</math>
</big>

One can also find &nbsp; ''lcm'' &nbsp; by merging the [[prime decomposition]]s of both &nbsp; ''m'' &nbsp; and &nbsp; ''n''.


;Related task
:* &nbsp; [https://rosettacode.org/wiki/Greatest_common_divisor greatest common divisor].


;See also:
* &nbsp; MathWorld entry: &nbsp; [http://mathworld.wolfram.com/LeastCommonMultiple.html Least Common Multiple].
* &nbsp; Wikipedia entry: &nbsp; [[wp:Least common multiple|Least common multiple]].
<br><br>

