LCM
least common multiple
number theory
math tutorial
arithmetic

Finding the LCM of a range of numbers

Data Structures & Algorithms practice on Codemia

Step through 300 algorithm problems with animated visualisers that show the data structure changing as the code runs.

Practice algorithms

Finding the least common multiple (LCM) of a range of numbers is a fundamental concept in mathematics, particularly useful in number theory and algebra. The LCM of a set of numbers is the smallest positive number that is evenly divisible by each number in the set. This article delves into the various methods to find the LCM of a range of numbers and outlines practical examples and technical insights.

What is the Least Common Multiple?

Given a set of integers, the LCM is the smallest positive integer that each of the integers divides without leaving a remainder. For instance, the LCM of 3 and 5 is 15 because 15 is the smallest number that both 3 and 5 divide without a remainder. This concept is particularly useful when dealing with problems in fractions, algebraic expressions, and optimizing calculations involving multiple terms.

Methods for Finding the LCM

1. Prime Factorization

Prime factorization involves breaking down each number in the set into its prime factors and then taking the highest power of all the primes that appear:

Steps:

  1. List the prime factors of each number.
  2. Identify the highest power of each prime number present.
  3. Multiply these highest powers to get the LCM.

Example: Find the LCM of 8 and 12. • Prime factors of 8: 232^3. • Prime factors of 12: 22×312^2 \times 3^1. • Highest powers: 23,312^3, 3^1. • LCM: 23×3=242^3 \times 3 = 24.

2. The Ladder Method (Division)

The ladder method, also known as the division method, systematically divides the numbers by common prime factors until only ones remain:

Steps:

  1. Write the numbers side by side.
  2. Divide them by the smallest prime number that can divide at least one of the numbers.
  3. Continue dividing until all numbers are reduced to 1.
  4. The LCM is the product of all divisors used.

Example: Find the LCM of 18 and 24. • Divide by 2: 18,249,12\frac{18, 24}{9, 12}

• Divide by 3: 9,123,4\frac{9, 12}{3, 4}

• Divide by 3: 3,41,4\frac{3, 4}{1, 4}

• Divide by 2: 1,41,2\frac{1, 4}{1, 2}

• Divide by 2: 1,21,1\frac{1, 2}{1, 1}

• LCM: 2×3×3×2×2=722 \times 3 \times 3 \times 2 \times 2 = 72.

3. Listing Multiples

Listing multiples is often impractical for large numbers but beneficial for smaller numbers or educational purposes:

Steps:

  1. List some multiples of each number.
  2. Identify the smallest common multiple.

Example: Find the LCM of 4 and 5. • Multiples of 4: 4, 8, 12, 16, 20, 24, ... • Multiples of 5: 5, 10, 15, 20, 25, ... • LCM: 20.

LCM of a Range of Numbers

The challenge increases when finding the LCM of more than two numbers. The following method can be employed:

1. Sequential LCM Calculation

Sequentially calculate the LCM by pairing numbers, which reduces the computational complexity:

Example: Find the LCM of 4, 5, and 6. • Calculate LCM of (4, 5), which is 20. • Calculate LCM of (20, 6), which is 60. • Thus, LCM of 4, 5, and 6 is 60.

2. Using the LCM formula

A general formula can be used for two numbers and extended to n numbers. For two numbers a and b:

LCM(a,b)=a×bGCD(a,b)\text{LCM}(a, b) = \frac{|a \times b|}{\text{GCD}(a, b)}

Where GCD is the greatest common divisor.

Example: Find the LCM of 12 and 18. • GCD(12,18)=6\text{GCD}(12, 18) = 6LCM(12,18)=12×186=36LCM(12, 18) = \frac{12 \times 18}{6} = 36

For more than two numbers, the formula can be extended iteratively:

LCM(a_1,a_2,...,a_n)=LCM(...(LCM(LCM(a_1,a_2),a_3),...)a_n)\text{LCM}(a\_1, a\_2, ..., a\_n) = \text{LCM}(...(\text{LCM}(\text{LCM}(a\_1, a\_2), a\_3), ...)a\_n)

Summary Table

MethodDescriptionBest ForExamples
Prime FactorizationHighest power of each prime factorSmall to medium numbers8, 12 => 24
Ladder (Division)Divide numbers by common primesAny range of numbers18, 24 => 72
Listing MultiplesList multiples and find smallestSmall numbers4, 5 => 20
Sequential LCM CalculationPairwise LCM calculationsLarger sets4, 5, 6 => 60
LCM FormulaUse GCD for calculationsGeneral purpose12, 18 => 36

Conclusion

Finding the LCM is a crucial mathematical operation with applications spanning various mathematical disciplines. Whether using prime factorization, division method, or leveraging computational formulas, understanding how to determine the LCM can solve a wide array of problems efficiently. Experiment with these methods to see which works best for different scenarios, sizes, and ranges of numbers.


Related reading
Course
Intermediate
27 lessons
15 hours
DSA Fundamentals

Master algorithmic patterns and data structures through hands-on LeetCode-style problems - from arrays and hashing to dynamic programming and advanced graphs.

View the course
Track what you have practised

A free account saves your progress, solutions and study plan across every problem on Codemia.

Data Structures & Algorithms practice on Codemia

Step through 300 algorithm problems with animated visualisers that show the data structure changing as the code runs.

Practice algorithms

All Rights Reserved.