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.
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:
- List the prime factors of each number.
- Identify the highest power of each prime number present.
- Multiply these highest powers to get the LCM.
• Example: Find the LCM of 8 and 12. • Prime factors of 8: . • Prime factors of 12: . • Highest powers: . • LCM: .
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:
- Write the numbers side by side.
- Divide them by the smallest prime number that can divide at least one of the numbers.
- Continue dividing until all numbers are reduced to 1.
- The LCM is the product of all divisors used.
• Example: Find the LCM of 18 and 24. • Divide by 2:
• Divide by 3:
• Divide by 3:
• Divide by 2:
• Divide by 2:
• LCM: .
3. Listing Multiples
Listing multiples is often impractical for large numbers but beneficial for smaller numbers or educational purposes:
• Steps:
- List some multiples of each number.
- 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:
Where GCD is the greatest common divisor.
• Example: Find the LCM of 12 and 18. • •
For more than two numbers, the formula can be extended iteratively:
Summary Table
| Method | Description | Best For | Examples |
| Prime Factorization | Highest power of each prime factor | Small to medium numbers | 8, 12 => 24 |
| Ladder (Division) | Divide numbers by common primes | Any range of numbers | 18, 24 => 72 |
| Listing Multiples | List multiples and find smallest | Small numbers | 4, 5 => 20 |
| Sequential LCM Calculation | Pairwise LCM calculations | Larger sets | 4, 5, 6 => 60 |
| LCM Formula | Use GCD for calculations | General purpose | 12, 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
- Finding the line along the intersection of two planes
- Finding the Nth Twin Prime
- Finding the number of digits of an integer
- Finding the smallest set of rectangles that covers the given rectilinear simple polygons
- Finding the squares in a plane given n points
- finding the width of a binary tree
- Finding unreachable sections of a 2D map
- Finding whether a point lies inside a rectangle or not

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 courseTrack 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.