RosettaCodeData/Task/Least-common-multiple/00DESCRIPTION

25 lines
1.3 KiB
Text
Raw Permalink Normal View History

2016-12-05 22:15:40 +01:00
;Task:
2013-04-10 21:29:02 -07:00
Compute the least common multiple of two integers.
2016-12-05 22:15:40 +01:00
Given   ''m''   and   ''n'',   the least common multiple is the smallest positive integer that has both   ''m''   and   ''n''   as factors.
2013-04-10 21:29:02 -07:00
2016-12-05 22:15:40 +01:00
;Example:
The least common multiple of 12 and 18 is 36, because 12 is a factor (12 × 3 = 36), and 18 is a factor (18 × 2 = 36), and there is no positive integer less than 36 that has both factors.   As a special case, if either   ''m''   or   ''n''   is zero, then the least common multiple is zero.
2013-04-10 21:29:02 -07:00
2016-12-05 22:15:40 +01:00
One way to calculate the least common multiple is to iterate all the multiples of   ''m'',   until you find one that is also a multiple of   ''n''.
2013-04-10 21:29:02 -07:00
2016-12-05 22:15:40 +01:00
If you already have   ''gcd''   for [[greatest common divisor]],   then this formula calculates   ''lcm''.
2013-04-10 21:29:02 -07:00
2016-12-05 22:15:40 +01:00
<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''.
2018-06-22 20:57:24 +00:00
;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]].
2016-12-05 22:15:40 +01:00
<br><br>