Least common multiple
In arithmetic and number theory, the least common multiple, lowest common multiple, or smallest common multiple of two integers a and b, usually denoted by lcm(a, b), is the smallest positive integer that is divisible by both a and b.^{[1]}^{[2]} Since division of integers by zero is undefined, this definition has meaning only if a and b are both different from zero.^{[3]} However, some authors define lcm(a,0) as 0 for all a, which is the result of taking the lcm to be the least upper bound in the lattice of divisibility.
The lcm is the "lowest common denominator" (lcd) that can be used before fractions can be added, subtracted or compared. The lcm of more than two integers is also welldefined: it is the smallest positive integer that is divisible by each of them.^{[1]}
Overview
A multiple of a number is the product of that number and an integer. For example, 10 is a multiple of 5 because 5 × 2 = 10, so 10 is divisible by 5 and 2. Because 10 is the smallest positive integer that is divisible by both 5 and 2, it is the least common multiple of 5 and 2. By the same principle, 10 is the least common multiple of −5 and −2 as well.
Notation
The least common multiple of two integers a and b is denoted as lcm(a, b).^{[1]} Some older textbooks use [a, b].^{[3]}^{[4]}
Example
 [math]\displaystyle{ \operatorname{lcm}(4, 6) }[/math]
Multiples of 4 are:
 [math]\displaystyle{ 4, 8, 12, 16, 20, 24, 28, 32, 36, 40, 44, 48, 52, 56, 60, 64, 68, 72, 76, ... }[/math]
Multiples of 6 are:
 [math]\displaystyle{ 6, 12, 18, 24, 30, 36, 42, 48, 54, 60, 66, 72, ... }[/math]
Common multiples of 4 and 6 are the numbers that are in both lists:
 [math]\displaystyle{ 12, 24, 36, 48, 60, 72, ... }[/math]
In this list, the smallest number is 12. Hence, the least common multiple is 12.
Applications
When adding, subtracting, or comparing simple fractions, the least common multiple of the denominators (often called the lowest common denominator) is used, because each of the fractions can be expressed as a fraction with this denominator. For example,
 [math]\displaystyle{ {2\over21}+{1\over6}={4\over42}+{7\over42}={11\over42} }[/math]
where the denominator 42 was used, because it is the least common multiple of 21 and 6.
Gears problem
Suppose there are two meshing gears in a machine, having m and n teeth, respectively, and the gears are marked by a line segment drawn from the center of the first gear to the center of the second gear. When the gears begin rotating, the number of rotations the first gear must complete to realign the line segment can be calculated by using [math]\displaystyle{ \operatorname{lcm}(m, n) }[/math]. The first gear must complete [math]\displaystyle{ \operatorname{lcm}(m, n)\over m }[/math] rotations for the realignment. By that time, the second gear will have made [math]\displaystyle{ \operatorname{lcm}(m, n)\over n }[/math] rotations.
Planetary alignment
Suppose there are three planets revolving around a star which take l, m and n units of time, respectively, to complete their orbits. Assume that l, m and n are integers. Assuming the planets started moving around the star after an initial linear alignment, all the planets attain a linear alignment again after [math]\displaystyle{ \operatorname{lcm}(l, m, n) }[/math] units of time. At this time, the first, second and third planet will have completed [math]\displaystyle{ \operatorname{lcm}(l, m, n)\over l }[/math], [math]\displaystyle{ \operatorname{lcm}(l, m, n)\over m }[/math] and [math]\displaystyle{ \operatorname{lcm}(l, m, n)\over n }[/math] orbits, respectively, around the star.^{[5]}
Calculation
Using the greatest common divisor
The following formula reduces the problem of computing the least common multiple to the problem of computing the greatest common divisor (gcd), also known as the greatest common factor:
 [math]\displaystyle{ \operatorname{lcm}(a,b)=\frac{ab}{\gcd(a,b)}. }[/math]
This formula is also valid when exactly one of a and b is 0, since gcd(a, 0) = a. However, if both a and b are 0, this formula would cause division by zero; lcm(0, 0) = 0 is a special case.
There are fast algorithms for computing the gcd that do not require the numbers to be factored, such as the Euclidean algorithm. To return to the example above,
 [math]\displaystyle{ \operatorname{lcm}(21,6) ={21\cdot6\over\gcd(21,6)} ={21\cdot6\over\gcd(3,6)} ={21\cdot 6\over 3}= \frac{126}{3} = 42. }[/math]
Because gcd(a, b) is a divisor of both a and b, it is more efficient to compute the lcm by dividing before multiplying:
 [math]\displaystyle{ \operatorname{lcm}(a,b)=\left({a\over\gcd(a,b)}\right)\cdot b=\left({b\over\gcd(a,b)}\right)\cdot a. }[/math]
This reduces the size of one input for both the division and the multiplication, and reduces the required storage needed for intermediate results (that is, overflow in the a×b computation). Because gcd(a, b) is a divisor of both a and b, the division is guaranteed to yield an integer, so the intermediate result can be stored in an integer. Implemented this way, the previous example becomes:
 [math]\displaystyle{ \operatorname{lcm}(21,6)={21\over\gcd(21,6)}\cdot6={21\over\gcd(3,6)}\cdot6={21\over3}\cdot6=7\cdot6=42. }[/math]
Using prime factorization
The unique factorization theorem indicates that every positive integer greater than 1 can be written in only one way as a product of prime numbers. The prime numbers can be considered as the atomic elements which, when combined, make up a composite number.
For example:
 [math]\displaystyle{ 90 = 2^1 \cdot 3^2 \cdot 5^1 = 2 \cdot 3 \cdot 3 \cdot 5. }[/math]
Here, the composite number 90 is made up of one atom of the prime number 2, two atoms of the prime number 3, and one atom of the prime number 5.
This fact can be used to find the lcm of a set of numbers.
Example: lcm(8,9,21)
Factor each number and express it as a product of prime number powers.
 [math]\displaystyle{ \begin{align} 8 & = 2^3 \\ 9 & = 3^2 \\ 21 & = 3^1 \cdot 7^1 \end{align} }[/math]
The lcm will be the product of multiplying the highest power of each prime number together. The highest power of the three prime numbers 2, 3, and 7 is 2^{3}, 3^{2}, and 7^{1}, respectively. Thus,
 [math]\displaystyle{ \operatorname{lcm}(8,9,21) = 2^3 \cdot 3^2 \cdot 7^1 = 8 \cdot 9 \cdot 7 = 504. }[/math]
This method is not as efficient as reducing to the greatest common divisor, since there is no known general efficient algorithm for integer factorization.
The same method can also be illustrated with a Venn diagram as follows, with the prime factorization of each of the two numbers demonstrated in each circle and all factors they share in common in the intersection. The lcm then can be found by multiplying all of the prime numbers in the diagram.
Here is an example:
 48 = 2 × 2 × 2 × 2 × 3,
 180 = 2 × 2 × 3 × 3 × 5,
sharing two "2"s and a "3" in common:
 Least common multiple = 2 × 2 × 2 × 2 × 3 × 3 × 5 = 720
 Greatest common divisor = 2 × 2 × 3 = 12
This also works for the greatest common divisor (gcd), except that instead of multiplying all of the numbers in the Venn diagram, one multiplies only the prime factors that are in the intersection. Thus the gcd of 48 and 180 is 2 × 2 × 3 = 12.
Using a simple algorithm
This method works easily for finding the lcm of several integers.
Let there be a finite sequence of positive integers X = (x_{1}, x_{2}, ..., x_{n}), n > 1. The algorithm proceeds in steps as follows: on each step m it examines and updates the sequence X^{(m)} = (x_{1}^{(m)}, x_{2}^{(m)}, ..., x_{n}^{(m)}), X^{(1)} = X, where X^{(m)} is the mth iteration of X, that is, X at step m of the algorithm, etc. The purpose of the examination is to pick the least (perhaps, one of many) element of the sequence X^{(m)}. Assuming x_{k0}^{(m)} is the selected element, the sequence X^{(m+1)} is defined as
 x_{k}^{(m+1)} = x_{k}^{(m)}, k ≠ k_{0}
 x_{k0}^{(m+1)} = x_{k0}^{(m)} + x_{k0}^{(1)}.
In other words, the least element is increased by the corresponding x whereas the rest of the elements pass from X^{(m)} to X^{(m+1)} unchanged.
The algorithm stops when all elements in sequence X^{(m)} are equal. Their common value L is exactly lcm(X).
For example, if X = X^{(1)} = (3, 4, 6), the steps in the algorithm produce:
 X^{(2)} = (6, 4, 6)
 X^{(3)} = (6, 8, 6)
 X^{(4)} = (6, 8, 12)  by choosing the second 6
 X^{(5)} = (9, 8, 12)
 X^{(6)} = (9, 12, 12)
 X^{(7)} = (12, 12, 12) so lcm = 12.
Using the tablemethod
This method works for any number of numbers. One begins by listing all of the numbers vertically in a table (in this example 4, 7, 12, 21, and 42):
 4
 7
 12
 21
 42
The process begins by dividing all of the numbers by 2. If 2 divides any of them evenly, write 2 in a new column at the top of the table, and the result of division by 2 of each number in the space to the right in this new column. If a number is not evenly divisible, just rewrite the number again. If 2 does not divide evenly into any of the numbers, repeat this procedure with the next largest prime number, 3 (see below).
×  2 

4  2 
7  7 
12  6 
21  21 
42  21 
Now, assuming that 2 did divide at least one number (as in this example), check if 2 divides again:
×  2  2 

4  2  1 
7  7  7 
12  6  3 
21  21  21 
42  21  21 
Once 2 no longer divides any number in the current column, repeat the procedure by dividing by the next larger prime, 3. Once 3 no longer divides, try the next larger primes, 5 then 7, etc. The process ends when all of the numbers have been reduced to 1 (the column under the last prime divisor consists only of 1's).
×  2  2  3  7 

4  2  1  1  1 
7  7  7  7  1 
12  6  3  1  1 
21  21  21  7  1 
42  21  21  7  1 
Now, multiply the numbers in the top row to obtain the lcm. In this case, it is 2 × 2 × 3 × 7 = 84.
As a general computational algorithm, the above is quite inefficient. One would never want to implement it in software: it takes too many steps and requires too much storage space. A far more efficient numerical algorithm can be obtained by using Euclid's algorithm to compute the gcd first, and then obtaining the lcm by division.
Formulas
Fundamental theorem of arithmetic
According to the fundamental theorem of arithmetic, a positive integer is the product of prime numbers, and this representation is unique up to the ordering of prime numbers:
 [math]\displaystyle{ n = 2^{n_2} 3^{n_3} 5^{n_5} 7^{n_7} \cdots = \prod_p p^{n_p}, }[/math]
where the exponents n_{2}, n_{3}, ... are nonnegative integers; for example, 84 = 2^{2} 3^{1} 5^{0} 7^{1} 11^{0} 13^{0} ...
Given two positive integers [math]\displaystyle{ a = \prod_p p^{a_p} }[/math] and [math]\displaystyle{ b = \prod_p p^{b_p} }[/math], their least common multiple and greatest common divisor are given by the formulas
 [math]\displaystyle{ \gcd(a,b) = \prod_p p^{\min(a_p, b_p)} }[/math]
and
 [math]\displaystyle{ \operatorname{lcm}(a,b) = \prod_p p^{\max(a_p, b_p)}. }[/math]
Since
 [math]\displaystyle{ \min(x,y) + \max(x,y) = x + y, }[/math]
this gives
 [math]\displaystyle{ \gcd(a,b) \operatorname{lcm}(a,b) = ab. }[/math]
In fact, every rational number can be written uniquely as the product of primes, if negative exponents are allowed. When this is done, the above formulas remain valid. For example:
 [math]\displaystyle{ \begin{align} 4 &= 2^2 3^0, & 6 &= 2^1 3^1, & \gcd(4, 6) &= 2^1 3^0 = 2, & \operatorname{lcm}(4,6) &= 2^2 3^1 = 12. \\[8pt] \tfrac{1}{3} &= 2^0 3^{1} 5^0, & \tfrac{2}{5} &= 2^1 3^0 5^{1}, & \gcd\left(\tfrac13, \tfrac{2}{5}\right) &= 2^0 3^{1} 5^{1} = \tfrac{1}{15}, & \operatorname{lcm}\left(\tfrac{1}{3}, \tfrac{2}{5}\right) &= 2^1 3^0 5^0 = 2, \\[8pt] \tfrac{1}{6} &= 2^{1} 3^{1}, & \tfrac{3}{4} &= 2^{2} 3^1, & \gcd\left(\tfrac{1}{6}, \tfrac{3}{4}\right) &= 2^{2} 3^{1} = \tfrac{1}{12}, & \operatorname{lcm}\left(\tfrac{1}{6}, \tfrac{3}{4}\right) &= 2^{1} 3^1 = \tfrac{3}{2}. \end{align} }[/math]
Latticetheoretic
The positive integers may be partially ordered by divisibility: if a divides b (that is, if b is an integer multiple of a) write a ≤ b (or equivalently, b ≥ a). (Note that the usual magnitudebased definition of ≤ is not used here.)
Under this ordering, the positive integers become a lattice, with meet given by the gcd and join given by the lcm. The proof is straightforward, if a bit tedious; it amounts to checking that lcm and gcd satisfy the axioms for meet and join. Putting the lcm and gcd into this more general context establishes a duality between them:
 If a formula involving integer variables, gcd, lcm, ≤ and ≥ is true, then the formula obtained by switching gcd with lcm and switching ≥ with ≤ is also true. (Remember ≤ is defined as divides).
The following pairs of dual formulas are special cases of general latticetheoretic identities.





It can also be shown^{[6]} that this lattice is distributive; that is, lcm distributes over gcd and gcd distributes over lcm:
 [math]\displaystyle{ \operatorname{lcm}(a,\gcd(b,c)) = \gcd(\operatorname{lcm}(a,b),\operatorname{lcm}(a,c)), }[/math]
 [math]\displaystyle{ \gcd(a,\operatorname{lcm}(b,c)) = \operatorname{lcm}(\gcd(a,b),\gcd(a,c)). }[/math]
This identity is selfdual:
 [math]\displaystyle{ \gcd(\operatorname{lcm}(a,b),\operatorname{lcm}(b,c),\operatorname{lcm}(a,c))=\operatorname{lcm}(\gcd(a,b),\gcd(b,c),\gcd(a,c)). }[/math]
Other
 Let D be the product of ω(D) distinct prime numbers (that is, D is squarefree).
Then^{[7]}
 [math]\displaystyle{ \{(x,y) \;:\; \operatorname{lcm}(x,y) = D\} = 3^{\omega(D)}, }[/math]
where the absolute bars  denote the cardinality of a set.
 If none of [math]\displaystyle{ a_1, a_2, \ldots , a_r }[/math] is zero, then
 [math]\displaystyle{ \operatorname{lcm}(a_1, a_2, \ldots , a_r) = \operatorname{lcm}(\operatorname{lcm}(a_1, a_2, \ldots , a_{r1}), a_r). }[/math]^{[8]}^{[9]}
In commutative rings
The least common multiple can be defined generally over commutative rings as follows: Let a and b be elements of a commutative ring R. A common multiple of a and b is an element m of R such that both a and b divide m (that is, there exist elements x and y of R such that ax = m and by = m). A least common multiple of a and b is a common multiple that is minimal, in the sense that for any other common multiple n of a and b, m divides n.
In general, two elements in a commutative ring can have no least common multiple or more than one. However, any two least common multiples of the same pair of elements are associates. In a unique factorization domain, any two elements have a least common multiple. In a principal ideal domain, the least common multiple of a and b can be characterised as a generator of the intersection of the ideals generated by a and b (the intersection of a collection of ideals is always an ideal).
See also
Notes
 ↑ ^{1.0} ^{1.1} ^{1.2} Weisstein, Eric W.. "Least Common Multiple" (in en). https://mathworld.wolfram.com/LeastCommonMultiple.html.
 ↑ Hardy & Wright, § 5.1, p. 48
 ↑ ^{3.0} ^{3.1} (Long 1972)
 ↑ (Pettofrezzo Byrkit)
 ↑ "nasa spacemath". https://spacemath.gsfc.nasa.gov/weekly/6Page41.pdf.
 ↑ The next three formulas are from Landau, Ex. III.3, p. 254
 ↑ Crandall & Pomerance, ex. 2.4, p. 101.
 ↑ (Long 1972)
 ↑ (Pettofrezzo Byrkit)
References
 Crandall, Richard; Pomerance, Carl (2001), Prime Numbers: A Computational Perspective, New York: Springer, ISBN 0387947779, https://books.google.com/books?id=8KZ4RQufxhYC&printsec=frontcover
 Hardy, G. H.; Wright, E. M. (1979), An Introduction to the Theory of Numbers (Fifth edition), Oxford: Oxford University Press, ISBN 9780198531715, https://books.google.com/books?id=3hTeH5VUheAC&dq&printsec=frontcover
 Landau, Edmund (1966), Elementary Number Theory, New York: Chelsea
 Long, Calvin T. (1972), Elementary Introduction to Number Theory (2nd ed.), Lexington: D. C. Heath and Company
 Pettofrezzo, Anthony J.; Byrkit, Donald R. (1970), Elements of Number Theory, Englewood Cliffs: Prentice Hall
Original source: https://en.wikipedia.org/wiki/ Least common multiple.
Read more 