freeCodeCamp/guide/english/mathematics/least-common-multiple/index.md

1.2 KiB

title
Least Common Multiple

Least Common Multiple

The least common multiple (LCM) of two or more numbers is the smallest number (not counting 0) which is a multiple of all of the numbers.
A common multiple is a number that is a multiple of two or more numbers. The common multiples of 4 and 5 are 0, 20, 40...
The least common multiple (LCM) of two numbers is the smallest number (not zero) that is a multiple of both.
Multiples of 4: 0, 4, 8, 12, 16, 20, 24, 28, 32, 36, 40, 44...
Multiples of 5: 0, 5, 10, 15, 20, 25, 30, 35, 40, 45, 50, 55...

Clearly, the Least Common Multiple of 4 and 5 is 20.

Let us learn how to calculate the Least Common Multiple

Step 1: List down all the prime factors of each number

e.g. Consider the numbers 30 and 40.
30 = 2 x 3 x 5
40 = 2 x 2 x 2 x 5

Step 2: Multiply each factor the greatest number of times it occurs in either number. If the same factor occurs more than once in both numbers, you multiply the factor the greatest number of times it occurs.

Occurences of 2: 3
Occurences of 3: 1
Occurences of 5: 1
LCM(30,40) = 2 x 2 x 2 x 3 x 5 = 120