Math & Basic

GCD & LCM Calculator

Greatest common divisor and least common multiple.

What is the GCD & LCM Calculator?

The greatest common divisor (GCD) is the largest number that evenly divides two or more integers, while the least common multiple (LCM) is the smallest number that is a multiple of all of them. This tool accepts comma-separated integers and computes both instantly.

How to use it

Enter two or more positive integers separated by commas, e.g. 12, 18, 24, then press Calculate. Decimals, negatives, and zero are not accepted.

Formula & process

Euclidean algorithm: GCD(a, b) = GCD(b, a mod b), repeated until b is 0. LCM(a, b) = (a × b) ÷ GCD(a, b). For three or more numbers, the result accumulates pairwise in order.

Examples
InputGCDLCM
12, 18636
12, 18, 24672
Tiling a floor (GCD) and buses meeting up (LCM) — two everyday calculations

To tile a 360cm × 240cm room completely with square tiles and no leftover scraps, the largest usable tile side must equal the greatest common divisor of the two lengths. GCD(360, 240)=120, so a 120cm tile gives 360÷120=3 tiles across and 240÷120=2 tiles down — 6 tiles total, with no gaps. Pick an arbitrary 100cm tile instead, and neither 360 nor 240 divides evenly by 100, leaving scrap pieces at the edges.

Bus schedules use the LCM the opposite way. If a Route A bus arrives every 12 minutes and a Route B bus every 18 minutes, and both depart together at 9:00 AM, they next depart together after the least common multiple of the two intervals. LCM(12, 18)=36, so they meet again 36 minutes later, at 9:36 AM. Tiling finds the "largest shared unit that still fits" (GCD), while bus schedules find the "shared cycle where both realign" (LCM) — opposite uses of the same pair of integers.

The Euclidean algorithm in one line

The Euclidean algorithm repeatedly replaces the larger number with the remainder of dividing it by the smaller, until the remainder reaches 0. For GCD(48, 18): 48 mod 18 = 12 → continue with (18, 12); 18 mod 12 = 6 → continue with (12, 6); 12 mod 6 = 0, so the last nonzero remainder, 6, is the GCD. This calculator uses the exact same method internally, finding the GCD of even very large numbers in just a few steps.

How is the GCD calculated?
This tool uses the Euclidean algorithm: for two numbers a and b, it repeatedly replaces (a, b) with (b, a mod b) until the remainder is 0 — the last nonzero b is the GCD. For three or more numbers, GCD is accumulated pairwise from left to right.
How is the LCM calculated?
The LCM of two numbers a and b is (a×b) ÷ GCD(a,b). For multiple numbers, the LCM of the first two is computed, then combined with each subsequent value in order.
Can I enter negative numbers or zero?
This tool only supports positive integers of 1 or greater. Zero, negative numbers, or decimals will show an error, and you must enter two or more comma-separated integers.
How is GCD used when tiling a floor?
To tile a 360cm × 240cm room completely with square tiles and no scraps, the largest usable tile side must equal the GCD of the two lengths. GCD(360, 240)=120, so a 120cm tile fits 3 across and 2 down with no gaps.
How do I use LCM to find when two buses with different intervals depart together again?
If a bus every 12 minutes and a bus every 18 minutes depart together at 9:00 AM, they next depart together after the LCM of the two intervals. LCM(12, 18)=36, so they align again 36 minutes later, at 9:36 AM.