03 · UNDERSTAND THE METHOD
How the gcd & lcm calculator works
The greatest common divisor, or GCD, is the largest positive integer that divides both input integers without a remainder. The least common multiple, or LCM, is the smallest positive multiple shared by two nonzero integer magnitudes. This calculator provides both results because they answer related but different questions. GCD helps reduce fractions or group objects evenly; LCM helps align repeating cycles or find a common denominator.
The formula and its variables
- a, b
- Integer inputs.
- g
- Greatest common divisor of the input magnitudes.
- LCM
- Least common multiple, conventionally zero when one input is zero.
The calculation, step by step
- Enter two whole-number integers within the accepted range. The calculation uses absolute magnitudes when finding positive factors and multiples.
- Use Euclid’s algorithm: replace a pair with the second number and the remainder until the remainder is zero. The last nonzero value is the GCD.
- Divide one input by the GCD before multiplying by the other to obtain the LCM. Handle a zero input separately rather than dividing by zero.
A worked example
For 12 and 18, common divisors are 1, 2, 3, and 6, so GCD is 6. The LCM is (12 ÷ 6) × 18 = 36. Two cycles lasting 12 and 18 time units align every 36 units when they start together. A fraction 12/18 reduces by the GCD to 2/3.
| First integer | 12 |
|---|---|
| Second integer | 18 |
| Greatest common divisor | 6 |
How to read the result and visual
The divisor describes the largest equal grouping possible for both numbers. The multiple describes the earliest shared repetition under integer cycles. When numbers have no shared factor besides one, the GCD is one and their LCM is the product of their magnitudes. Equal positive inputs produce the same value for both results.
Assumptions, rounding, and limitations
These operations use integers, not fractional measurement durations or arbitrary real numbers. Decimal inputs should be scaled deliberately into integers before use. Very large LCM products can exceed exact browser integer precision and are constrained by validation. A zero pair is handled by explicit conventions rather than by claiming a largest positive divisor of both zeros.
Frequently asked questions
Can I enter negative integers?
This tool accepts nonnegative integers. For a negative integer, enter its absolute magnitude to obtain the positive GCD and LCM.
Why is LCM useful for fractions?
A common denominator must be a multiple of each denominator; the least common multiple provides the smallest positive choice.