LCM Calculator - Elementor Compatible

LCM Calculator

Use this calculator to find the Least Common Multiple (LCM) of two or more numbers. Enter numbers separated by commas and click Calculate. Step-by-step solutions using all three methods are shown below.

i
Enter numbers separated by a comma "," and click the Calculate button
Please enter valid positive integers separated by commas.
Results
- Least Common Multiple (LCM)
Input Numbers
-
Count of Numbers
-
Note: The LCM of two or more integers is the smallest positive integer divisible by all of them. LCM is widely used in fraction arithmetic (finding common denominators), scheduling problems, and number theory.

What is the Least Common Multiple (LCM)?

In mathematics, the Least Common Multiple (LCM) of two or more integers is the smallest positive integer that is divisible by each of them. It is commonly denoted as LCM(a, b).

Prime Factorization Method

Break each number into its prime factors. The LCM is the product of the highest power of every prime that appears in any factorization.

EX: Find LCM(21, 14, 38) 21 = 3 x 7 14 = 2 x 7 38 = 2 x 19 LCM = 3^1 x 7^1 x 2^1 x 19^1 = 798

GCF / GCD Method

Using the Greatest Common Factor: LCM(a, b) = (a x b) / GCF(a, b). For more than two numbers, apply the formula iteratively.

EX: LCM(14, 38) GCF(14, 38) = 2 LCM(14, 38) = (14 x 38) / 2 = 266 LCM(266, 21) GCF(266, 21) = 7 LCM(266, 21) = (266 x 21) / 7 = 798

Listing Multiples (Brute Force)

List multiples of each number until a common multiple is found. The first (smallest) match is the LCM.

EX: Find LCM(18, 26) 18: 18, 36, 54, 72, 90, 108, 126, 144, 162, 180, 198, 216, 234 26: 52, 78, 104, 130, 156, 182, 208, 234 LCM(18, 26) = 234
'; return; } var html = '
'; var current = nums[0]; html += '
Start with: ' + current + '
'; for (var i = 1; i < nums.length; i++) { var next = nums[i]; var g = self.gcd(current, next); var newLcm = (current / g) * next; html += '
'; html += '
LCM(' + current.toLocaleString() + ', ' + next.toLocaleString() + ')
'; html += '
GCF(' + current.toLocaleString() + ', ' + next.toLocaleString() + ') = ' + g + '\nLCM = (' + current.toLocaleString() + ' x ' + next.toLocaleString() + ') / ' + g + ' = ' + newLcm.toLocaleString() + '
'; html += '
'; current = newLcm; } html += '
LCM(' + nums.join(', ') + ') = ' + result.toLocaleString() + '
'; html += '
'; document.getElementById('lcmMethod2Body').innerHTML = html; }, renderMethod3: function (nums, result) { var html = '
'; if (result > 500000 || nums.length > 5) { html += '

Numbers are too large or too many to list multiples efficiently. The LCM is ' + result.toLocaleString() + '.

'; } else { var maxRow = Math.min(50, result / Math.min.apply(null, nums)); var table = ''; nums.forEach(function(n) { table += ''; }); table += ''; for (var r = 1; r <= maxRow; r++) { var isLcmRow = nums.some(function(n) { return n * r === result; }); table += ''; nums.forEach(function(n) { var val = n * r; var cls = (val === result) ? ' class="lcm-highlight"' : ''; table += '' + val.toLocaleString() + ''; }); table += ''; if (isLcmRow) break; } table += '
Multiples of ' + n + '
'; html += '

Listing multiples of each number until a common value is found:

'; html += table; html += '
First common multiple = LCM = ' + result.toLocaleString() + '
'; } html += '
'; document.getElementById('lcmMethod3Body').innerHTML = html; }, toggleMethod: function (n) { var body = document.getElementById('lcmMethod' + n + 'Body'); var icon = document.getElementById('lcmToggle' + n + 'Icon'); body.classList.toggle('lcm-show'); icon.innerHTML = body.classList.contains('lcm-show') ? '▲' : '▼'; }, clear: function () { document.getElementById('lcmNumbersInput').value = ''; document.getElementById('lcmResultSection').classList.remove('lcm-show'); document.getElementById('lcmError').classList.remove('lcm-show'); for (var n = 1; n <= 3; n++) { document.getElementById('lcmMethod' + n + 'Body').classList.remove('lcm-show'); document.getElementById('lcmToggle' + n + 'Icon').innerHTML = '▼'; } this.lastResult = null; }, exportPDF: function () { if (!this.lastResult) { alert('Please calculate LCM first.'); return; } var self = this; var jsPDF = window.jspdf.jsPDF; var doc = new jsPDF(); var green = [61, 122, 42]; var dark = [45, 55, 72]; var light = [113, 128, 150]; var nums = this.lastResult.nums; var result = this.lastResult.result; doc.setFontSize(22); doc.setTextColor(green[0], green[1], green[2]); doc.setFont(undefined, 'bold'); doc.text('LCM Calculator', 105, 20, { align: 'center' }); doc.setFontSize(11); doc.setTextColor(light[0], light[1], light[2]); doc.setFont(undefined, 'normal'); doc.text('Least Common Multiple - Step-by-Step Report', 105, 28, { align: 'center' }); doc.setDrawColor(green[0], green[1], green[2]); doc.setLineWidth(0.5); doc.line(20, 32, 190, 32); doc.setFillColor(230, 244, 225); doc.roundedRect(20, 38, 170, 24, 3, 3, 'F'); doc.setFontSize(9); doc.setTextColor(light[0], light[1], light[2]); doc.text('Least Common Multiple (LCM)', 105, 45, { align: 'center' }); doc.setFontSize(22); doc.setTextColor(green[0], green[1], green[2]); doc.setFont(undefined, 'bold'); doc.text(result.toLocaleString(), 105, 55, { align: 'center' }); var y = 72; doc.setFontSize(10); doc.setTextColor(dark[0], dark[1], dark[2]); doc.setFont(undefined, 'normal'); doc.text('Input Numbers: ' + nums.join(', '), 20, y); doc.text('Count: ' + nums.length, 160, y); y += 12; // Method 1 doc.setFillColor(green[0], green[1], green[2]); doc.rect(20, y - 5, 170, 8, 'F'); doc.setFontSize(10); doc.setTextColor(255, 255, 255); doc.setFont(undefined, 'bold'); doc.text('Method 1: Prime Factorization', 22, y); y += 10; var allFactors = {}; nums.forEach(function(n) { var f = self.primeFactors(n); doc.setFontSize(9); doc.setTextColor(dark[0], dark[1], dark[2]); doc.setFont(undefined, 'normal'); doc.text(n + ' = ' + self.factorString(n), 22, y); y += 6; Object.keys(f).forEach(function(p) { if (!allFactors[p] || allFactors[p] < f[p]) allFactors[p] = f[p]; }); }); var parts = []; Object.keys(allFactors).sort(function(a,b){return a-b;}).forEach(function(p) { parts.push(allFactors[p] > 1 ? p + '^' + allFactors[p] : String(p)); }); doc.setFontSize(9); doc.setTextColor(dark[0], dark[1], dark[2]); doc.text('Highest powers: ' + parts.join(' x '), 22, y); y += 6; doc.setFont(undefined, 'bold'); doc.setTextColor(green[0], green[1], green[2]); doc.text('LCM = ' + parts.join(' x ') + ' = ' + result.toLocaleString(), 22, y); y += 12; // Method 2 if (y > 250) { doc.addPage(); y = 20; } doc.setFillColor(green[0], green[1], green[2]); doc.rect(20, y - 5, 170, 8, 'F'); doc.setFontSize(10); doc.setTextColor(255, 255, 255); doc.setFont(undefined, 'bold'); doc.text('Method 2: GCF / GCD Method', 22, y); y += 10; var current = nums[0]; doc.setFontSize(9); doc.setTextColor(dark[0], dark[1], dark[2]); doc.setFont(undefined, 'normal'); doc.text('Start with: ' + current, 22, y); y += 6; for (var i = 1; i < nums.length; i++) { var next = nums[i]; var g = self.gcd(current, next); var newLcm = (current / g) * next; if (y > 270) { doc.addPage(); y = 20; } doc.text('GCF(' + current.toLocaleString() + ', ' + next.toLocaleString() + ') = ' + g, 22, y); y += 5; doc.text('LCM(' + current.toLocaleString() + ', ' + next.toLocaleString() + ') = (' + current.toLocaleString() + ' x ' + next.toLocaleString() + ') / ' + g + ' = ' + newLcm.toLocaleString(), 22, y); y += 7; current = newLcm; } doc.setFont(undefined, 'bold'); doc.setTextColor(green[0], green[1], green[2]); doc.text('LCM(' + nums.join(', ') + ') = ' + result.toLocaleString(), 22, y); y += 12; // Method 3 if (y > 250) { doc.addPage(); y = 20; } doc.setFillColor(green[0], green[1], green[2]); doc.rect(20, y - 5, 170, 8, 'F'); doc.setFontSize(10); doc.setTextColor(255, 255, 255); doc.setFont(undefined, 'bold'); doc.text('Method 3: Listing Multiples (Brute Force)', 22, y); y += 10; if (result <= 500000 && nums.length <= 5) { var colW = Math.floor(160 / nums.length); doc.setFillColor(74, 154, 58); doc.setTextColor(255, 255, 255); doc.setFont(undefined, 'bold'); doc.setFontSize(8); nums.forEach(function(n, ci) { doc.rect(20 + ci * colW, y - 4, colW, 7, 'F'); doc.text('x' + n, 20 + ci * colW + 2, y); }); y += 7; var maxRow = Math.min(50, result / Math.min.apply(null, nums)); for (var r = 1; r <= maxRow; r++) { if (y > 270) { doc.addPage(); y = 20; break; } var isLcmRow = nums.some(function(n) { return n * r === result; }); if (isLcmRow) { doc.setFillColor(212, 234, 205); doc.rect(20, y - 4, colW * nums.length, 6, 'F'); } doc.setFont(undefined, isLcmRow ? 'bold' : 'normal'); doc.setTextColor(isLcmRow ? green[0] : dark[0], isLcmRow ? green[1] : dark[1], isLcmRow ? green[2] : dark[2]); doc.setFontSize(8); nums.forEach(function(n, ci) { doc.text((n * r).toLocaleString(), 20 + ci * colW + 2, y); }); y += 5; if (isLcmRow) break; } y += 4; doc.setFont(undefined, 'bold'); doc.setTextColor(green[0], green[1], green[2]); doc.setFontSize(9); doc.text('First common multiple (LCM) = ' + result.toLocaleString(), 22, y); } else { doc.setFontSize(9); doc.setTextColor(dark[0], dark[1], dark[2]); doc.setFont(undefined, 'normal'); doc.text('Numbers too large to list multiples. LCM = ' + result.toLocaleString(), 22, y); } var pages = doc.internal.getNumberOfPages(); for (var pg = 1; pg <= pages; pg++) { doc.setPage(pg); doc.setFontSize(7); doc.setTextColor(light[0], light[1], light[2]); doc.setFont(undefined, 'italic'); doc.text('Generated on ' + new Date().toLocaleString() + ' | Page ' + pg + ' of ' + pages, 105, 287, { align: 'center' }); } doc.save('lcm-report.pdf'); } }; if (document.readyState === 'loading') { document.addEventListener('DOMContentLoaded', function() { LCMCalc.init(); }); } else { LCMCalc.init(); } })();