|
| 1 | +# Least common multiple |
| 2 | + |
| 3 | +In arithmetic and number theory, the least common multiple, |
| 4 | +lowest common multiple, or smallest common multiple of |
| 5 | +two integers `a` and `b`, usually denoted by `LCM(a, b)`, is |
| 6 | +the smallest positive integer that is divisible by |
| 7 | +both `a` and `b`. Since division of integers by zero is |
| 8 | +undefined, this definition has meaning only if `a` and `b` are |
| 9 | +both different from zero. However, some authors define `lcm(a,0)` |
| 10 | +as `0` for all `a`, which is the result of taking the `lcm` |
| 11 | +to be the least upper bound in the lattice of divisibility. |
| 12 | + |
| 13 | +## Example |
| 14 | + |
| 15 | +What is the LCM of 4 and 6? |
| 16 | + |
| 17 | +Multiples of `4` are: |
| 18 | + |
| 19 | +``` |
| 20 | +4, 8, 12, 16, 20, 24, 28, 32, 36, 40, 44, 48, 52, 56, 60, 64, 68, 72, 76, ... |
| 21 | +``` |
| 22 | + |
| 23 | +and the multiples of `6` are: |
| 24 | + |
| 25 | +``` |
| 26 | +6, 12, 18, 24, 30, 36, 42, 48, 54, 60, 66, 72, ... |
| 27 | +``` |
| 28 | + |
| 29 | +Common multiples of `4` and `6` are simply the numbers |
| 30 | +that are in both lists: |
| 31 | + |
| 32 | +``` |
| 33 | +12, 24, 36, 48, 60, 72, .... |
| 34 | +``` |
| 35 | + |
| 36 | +So, from this list of the first few common multiples of |
| 37 | +the numbers `4` and `6`, their least common multiple is `12`. |
| 38 | + |
| 39 | +## Computing the least common multiple |
| 40 | + |
| 41 | +The following formula reduces the problem of computing the |
| 42 | +least common multiple to the problem of computing the greatest |
| 43 | +common divisor (GCD), also known as the greatest common factor: |
| 44 | + |
| 45 | +``` |
| 46 | +lcm(a, b) = |a * b| / gcd(a, b) |
| 47 | +``` |
| 48 | + |
| 49 | + |
| 50 | + |
| 51 | +A Venn diagram showing the least common multiples of |
| 52 | +combinations of `2`, `3`, `4`, `5` and `7` (`6` is skipped as |
| 53 | +it is `2 × 3`, both of which are already represented). |
| 54 | + |
| 55 | +For example, a card game which requires its cards to be |
| 56 | +divided equally among up to `5` players requires at least `60` |
| 57 | +cards, the number at the intersection of the `2`, `3`, `4` |
| 58 | +and `5` sets, but not the `7` set. |
| 59 | + |
| 60 | +## References |
| 61 | + |
| 62 | +[Wikipedia](https://en.wikipedia.org/wiki/Least_common_multiple) |
0 commit comments