Two ways to find the GCD and LCM
To see the prime factors of a single number with every division step, use the prime factorization calculator.
By prime factorisation
- Write each number as a product of primes: 12 = 2² × 3, 18 = 2 × 3², 30 = 2 × 3 × 5.
- For the GCD, take only the primes in every number, each to its lowest power: 2 × 3 = 6.
- For the LCM, take every prime that appears, each to its highest power: 2² × 3² × 5 = 180.
By the Euclidean algorithm
Divide the larger number by the smaller and keep the remainder, then repeat with the smaller number and that remainder. For 252 and 105: 252 = 105 × 2 + 42, 105 = 42 × 2 + 21, 42 = 21 × 2 + 0. The last non-zero remainder, 21, is the GCD. For more than two numbers, take the GCD of the first two, then of that result and the next number.
For two numbers the LCM follows directly: LCM = a × b ÷ GCD. For 252 and 105 that is 252 × 105 ÷ 21 = 1,260.
GCD or LCM? Reading a word problem
The two are easy to mix up in homework, because both take the same numbers. The question to ask is whether the answer has to be smaller than the numbers you were given or larger.
- Splitting things into equal groups — GCD. 48 red beads and 36 blue beads go into identical bags with none left over. The most bags you can make is GCD(48, 36) = 12, each holding 4 red and 3 blue.
- The biggest piece that fits exactly — GCD. The largest square tile that covers a 240 cm × 180 cm floor without cutting is 60 cm, because GCD(240, 180) = 60; the floor takes 4 × 3 = 12 tiles.
- Making two amounts match — LCM. Hot dogs come in packs of 10 and buns in packs of 8. The smallest number you can buy of each with none spare is LCM(10, 8) = 40: four packs of hot dogs and five of buns.
Words like “largest”, “greatest” or “equal groups” usually point to the GCD, and “smallest”, “next time” or “at the same time” to the LCM — but check the size of the answer rather than trusting the wording alone.
Where they are used
The LCM of denominators is the lowest common denominator for adding fractions, and it answers “when do two cycles line up again” — buses every 12 and 18 minutes next leave together after 36. The GCD simplifies fractions and ratios, and gives the largest equal groups or tiles that fit without a remainder. To simplify a ratio to lowest terms using exactly this idea, see the ratio calculator; to add, subtract, multiply or divide fractions with the LCM as the common denominator, use the fraction calculator.
Worked examples
- Two numbers with a large GCD, 270 and 192. 270 = 2 × 3³ × 5 and 192 = 2⁶ × 3. The shared primes are 2 and 3, each to its lowest power: GCD = 2 × 3 = 6. The LCM takes every prime to its highest power, 2⁶ × 3³ × 5 = 8,640, which also checks out against a × b ÷ GCD = 270 × 192 ÷ 6 = 8,640.
- Three numbers, 12, 18 and 30. 12 = 2² × 3, 18 = 2 × 3², 30 = 2 × 3 × 5. All three share only 2¹ and 3¹, so GCD = 6. The LCM needs 2², 3² and 5¹: 4 × 9 × 5 = 180.
- Coprime numbers, 8 and 15. They share no prime factor, so GCD = 1 and the LCM is simply their product, 8 × 15 = 120 — the shortcut only works when the GCD is 1.
- A pair where one number divides the other, 9 and 36. 36 ÷ 9 = 4 exactly, so 9 is already a factor of 36: GCD = 9 and LCM = 36, the larger of the two numbers.
Edge cases and blocked input
- Fewer than two numbers, or more than ten, is rejected — the calculator needs at least a pair to compare and caps the list at ten to keep the working readable.
- Zero, negative numbers and decimals are refused with an explanation. GCD and LCM are defined for positive whole numbers; zero has no greatest divisor and negative numbers do not change the answer but are blocked to avoid confusion.
- A number above 999,999,999,999 is rejected as too large for this calculator.
- Duplicate numbers in the list, such as 12, 12, 18, are accepted — the GCD and LCM of a list are unaffected by repeats.
- One number that is a multiple of another, such as 9 and 36 above, is not an error; the GCD is simply the smaller number and the LCM the larger.
Common mistakes
- Using the a × b ÷ GCD shortcut for three or more numbers. It only holds for a pair; the FAQ below has the 12 × 18 = 216 check that fails once a third number joins the list.
- Mixing up which primes to keep. GCD keeps shared primes at their lowest power; LCM keeps every prime seen at its highest power. Writing both factorisations in full, lined up by prime, avoids the mix-up.
- Assuming the GCD of coprime numbers is their product. It is 1, by definition — the LCM is the product in that case, not the GCD.
- Stopping the Euclidean algorithm one step early. The GCD is the last non-zero remainder, not the remainder that comes right before a zero appears in the wrong column — keep dividing until the remainder is exactly 0.
Limitations
This calculator works with positive whole numbers only, from 2 to 10 of them, each up to 999,999,999,999. It does not handle negative numbers, decimals, or algebraic expressions. All the factorisation and division run in your browser; the numbers you enter are not sent anywhere.
Frequently asked questions
What is the greatest common divisor?
The largest whole number that divides every number in the list exactly. For 12 and 18 it is 6. It is also called the greatest common factor (GCF) or highest common factor (HCF).
What is the least common multiple?
The smallest positive whole number that every number in the list divides into exactly. For 12 and 18 it is 36. It is the lowest common denominator when adding fractions.
How do you find the GCD and LCM using prime factors?
Factorise each number. The GCD multiplies the primes they all share, each to its lowest power; the LCM multiplies every prime that appears, each to its highest power. 12 = 2² × 3 and 18 = 2 × 3², so the GCD is 2 × 3 = 6 and the LCM is 2² × 3² = 36.
What is the Euclidean algorithm?
Divide the larger number by the smaller and keep the remainder; then divide the smaller number by that remainder, and repeat until the remainder is 0. The last non-zero remainder is the GCD. It is fast even for very large numbers.
Is GCD × LCM always equal to the product of the numbers?
For two numbers, yes: 6 × 36 = 12 × 18 = 216. For three or more numbers it is not true in general, so the calculator only shows that check for a pair.
What does coprime mean?
Two or more numbers are coprime when their greatest common divisor is 1 — they share no prime factor. 8 and 15 are coprime, and their LCM is simply 8 × 15 = 120.
Which numbers can I enter?
Between 2 and 10 positive whole numbers, each up to 999,999,999,999, separated by spaces, commas or new lines. Zero, negative numbers and decimals are refused with an explanation.