LCM and GCD Calculator Widget

Add an HCF and LCM calculator to your number-theory or fractions lesson. Students enter two to ten whole numbers and get the greatest common divisor, the least common multiple and the line-by-line Euclidean algorithm that finds the GCD.

Education & Math Calculator Runs in your browser Free · no ads

Customize your widget

Theme
Auto follows the visitor's light/dark setting.
Style
Attribution on your page
Optional and entirely your choice. The exact line is shown in the code below; it links to the tool with rel="nofollow".
More options
Starting values
Leave blank to use the widget's defaults. Visitors can still change every value.

Live preview

Exactly what your visitors will see

Embed code

<iframe src="https://a2z.tools/embed/w/lcm-gcd-calculator" title="LCM and GCD Calculator by A2Z Tools" width="100%" height="580" style="border:0;width:100%" loading="lazy" allow="clipboard-write"></iframe>

A plain iframe. Works everywhere, including site builders that strip scripts. Adjust height if your content needs more room.

Works with

How it works

The greatest common divisor comes from Euclid's algorithm: divide the larger number by the smaller, keep the remainder, and repeat with the divisor and that remainder until the remainder is 0 - the last non-zero remainder is the GCD. For 1071 and 462 that takes three lines (147, 21, 0), giving 21. The least common multiple uses lcm(a, b) = a / gcd(a, b) x b, dividing first so intermediate values stay small. For three or more numbers both are folded pairwise from left to right. All arithmetic uses arbitrary-precision integers (BigInt), so numbers of up to 30 digits - and LCMs far beyond 2^53 - stay exact. The input accepts commas, spaces or semicolons between values. Zero is refused because every integer divides 0 and its LCM is undefined; negative numbers and decimals get their own explanations.

Calculation method

  • Euclid: a = q x b + r, then gcd(a, b) = gcd(b, r); stop when r = 0
  • lcm(a, b) = a / gcd(a, b) x b
  • More numbers: gcd(a, b, c) = gcd(gcd(a, b), c); likewise for lcm
  • Exact BigInt arithmetic, up to 30 digits per number

Worked examples

Three timetables

Inputs: 12, 18, 30

Result: GCD 6, LCM 180

12 = 2^2 x 3, 18 = 2 x 3^2, 30 = 2 x 3 x 5: shared 2 x 3 = 6; highest powers 2^2 x 3^2 x 5 = 180.

Euclid's classic

Inputs: 1071, 462

Result: GCD 21, LCM 23,562

1071 = 2 x 462 + 147; 462 = 3 x 147 + 21; 147 = 7 x 21 + 0.

Limitations

  • Whole positive numbers only; fractions, decimals and polynomials are not handled.
  • Euclid's steps are shown for the first two numbers only, at most 30 lines.
  • Prime factorisations of the inputs are not listed here; use the prime factorization calculator for that.

Where publishers use it

  • Middle-school lessons on factors, multiples and adding fractions
  • Competitive-exam preparation sites with HCF and LCM word problems
  • Scheduling puzzles: when do buses every 12, 18 and 30 minutes meet again
  • Programming tutorials explaining Euclid's algorithm
  • Gear and timing-belt articles that need the LCM of tooth counts

Questions

Is HCF the same as GCD?

Yes. Highest common factor (HCF) is the usual name in Indian and British schools; greatest common divisor (GCD) is common in the US and in computing. Both mean the largest number dividing all inputs exactly.

How are HCF and LCM related?

For two numbers, HCF x LCM = the product of the numbers. For 12 and 18: 6 x 36 = 216 = 12 x 18. This shortcut does not hold for three or more numbers.

When do buses every 12, 18 and 30 minutes leave together again?

After the LCM of the three intervals, 180 minutes. Their GCD is 6, so all three timetables also line up on 6-minute marks.

What does co-prime mean in the result?

That the GCD is 1: the numbers share no factor other than 1, like 8 and 15. For three or more numbers it means no single factor divides all of them, even if some pairs share one.

Why is 0 not accepted?

Every whole number divides 0, so 0 has no least common multiple with anything, and GCD with 0 is just the other number. The widget asks for numbers of 1 or more.

How does the LCM help when adding fractions?

The LCM of the denominators is the lowest common denominator. For 1/12 + 1/18 the LCM is 36, so the sum is 3/36 + 2/36 = 5/36, with smaller numbers than using 12 x 18 = 216.

Why do 13-year and 17-year cicadas rarely emerge together?

Their cycle lengths are prime, so the LCM is the product: 13 x 17 = 221 years between joint emergences of two such broods. Coprime periods line up as seldom as possible, a pattern biologists link to avoiding predators with shorter cycles.

Cite or recommend this tool

If you reference this tool in an article, course or documentation, these formats are ready to copy. They are optional - nothing is added to your site unless you paste it.

A2Z Tools LCM and GCD Calculator
https://a2z.tools/embed/lcm-gcd-calculator
  • Prime Factorization Calculator

    Education & Math Calculator New

    Prime test and prime factors with exponents for numbers up to one trillion, plus divisor count and sum.

    Get code
  • Fraction Calculator

    Education & Math Calculator

    Add, subtract, multiply and divide fractions and mixed numbers, with the simplified answer.

    Get code
  • Ratio Calculator

    Education & Math Calculator New

    Simplify a : b (decimals too), scale a ratio to a target amount, or solve a : b = c : x.

    Get code
  • Percentage Calculator

    Education & Math Calculator

    X% of Y, X as a percent of Y, and the percentage change between two values.

    Get code
  • Basic Calculator

    Education & Math Calculator

    A clean on-screen calculator with keyboard support, correct operator precedence and percent.

    Get code
  • Scientific Calculator

    Education & Math Calculator

    Trig in degrees or radians, logs, roots, powers, factorials, pi, e and Ans - typed or tapped.

    Get code

Preview