Least Common Multiple Calculator

Least Common Multiple (LCM) Calculator

Enter two or more integers to find their smallest common multiple.

Result:

function calculateLCM() { var input = document.getElementById("numberInput").value; var resultArea = document.getElementById("lcm-result-area"); var output = document.getElementById("lcm-output"); var steps = document.getElementById("lcm-steps"); // Split and parse input var numbers = input.split(",").map(function(item) { return parseInt(item.trim()); }); // Filter out NaNs and check if we have at least 2 numbers var validNumbers = numbers.filter(function(n) { return !isNaN(n) && n !== 0; }); if (validNumbers.length < 2) { alert("Please enter at least two valid non-zero integers."); return; } // GCD function (Greatest Common Divisor) function getGCD(a, b) { a = Math.abs(a); b = Math.abs(b); while (b) { var t = b; b = a % b; a = t; } return a; } // LCM function for two numbers function getLCM(a, b) { if (a === 0 || b === 0) return 0; return Math.abs(a * b) / getGCD(a, b); } // Calculate LCM of the array var currentLCM = validNumbers[0]; for (var i = 1; i < validNumbers.length; i++) { currentLCM = getLCM(currentLCM, validNumbers[i]); } // Display results resultArea.style.display = "block"; output.innerHTML = "LCM = " + currentLCM; steps.innerHTML = "The smallest number divisible by " + validNumbers.join(", ") + " is " + currentLCM + "."; }

What is the Least Common Multiple (LCM)?

The Least Common Multiple (LCM), also known as the Lowest Common Multiple or Smallest Common Multiple, is the smallest positive integer that is perfectly divisible by each of the numbers in a given set. In simpler terms, it is the first number that appears in the multiplication tables of all the numbers being compared.

How to Calculate LCM

There are several methods to find the LCM of a set of numbers. The most common methods include:

  • Listing Multiples: List the multiples of each number until you find the first one they all share.
  • Prime Factorization: Break each number down into its prime factors. Multiply the highest power of each prime factor present in any of the numbers.
  • GCD Formula: For two numbers $a$ and $b$, the LCM can be found using the Greatest Common Divisor (GCD):
    LCM(a, b) = |a × b| / GCD(a, b)

Practical Example: LCM of 12 and 15

Let's find the LCM of 12 and 15 using the listing method:

  • Multiples of 12: 12, 24, 36, 48, 60, 72, 84…
  • Multiples of 15: 15, 30, 45, 60, 75, 90…

The smallest number that appears in both lists is 60. Therefore, LCM(12, 15) = 60.

Real-World Application

LCM is frequently used in everyday scheduling and math problems. For instance, if one bus arrives every 8 minutes and another every 12 minutes, the LCM (24) tells you that both buses will arrive at the same time every 24 minutes. It is also essential for adding or subtracting fractions with different denominators, where the LCM serves as the Least Common Denominator (LCD).

Quick Tips for LCM

  • If one number is a multiple of the other (e.g., 5 and 10), the larger number (10) is the LCM.
  • If the numbers are prime (e.g., 7 and 11), the LCM is simply their product (77).
  • The LCM will always be greater than or equal to the largest number in your set.

Leave a Comment