1 |
|
2 |
|
3 | # Function lcm
|
4 |
|
5 | Calculate the least common multiple for two or more values or arrays.
|
6 |
|
7 | lcm is defined as:
|
8 |
|
9 | lcm(a, b) = abs(a * b) / gcd(a, b)
|
10 |
|
11 | For matrices, the function is evaluated element wise.
|
12 |
|
13 |
|
14 | ## Syntax
|
15 |
|
16 | ```js
|
17 | math.lcm(a, b)
|
18 | math.lcm(a, b, c, ...)
|
19 | ```
|
20 |
|
21 | ### Parameters
|
22 |
|
23 | Parameter | Type | Description
|
24 | --------- | ---- | -----------
|
25 | `args` | ... number | BigNumber | Array | Matrix | Two or more integer numbers
|
26 |
|
27 | ### Returns
|
28 |
|
29 | Type | Description
|
30 | ---- | -----------
|
31 | number | BigNumber | Array | Matrix | The least common multiple
|
32 |
|
33 |
|
34 | ## Examples
|
35 |
|
36 | ```js
|
37 | math.lcm(4, 6) // returns 12
|
38 | math.lcm(6, 21) // returns 42
|
39 | math.lcm(6, 21, 5) // returns 210
|
40 |
|
41 | math.lcm([4, 6], [6, 21]) // returns [12, 42]
|
42 | ```
|
43 |
|
44 |
|
45 | ## See also
|
46 |
|
47 | [gcd](gcd.md),
|
48 | [xgcd](xgcd.md)
|