GCD and LCM Calculator

Find the greatest common divisor and least common multiple of two whole integers. Results use exact integer arithmetic, so large inputs do not lose precision through floating-point rounding.

How to use

Enter the first and second whole integers. Read the GCD/HCF and LCM results below the inputs. The tool recalculates when either value changes; Calculate repeats the calculation and Reset restores 48 and 18. Check the stated zero convention before using a zero input.

Formula

For nonzero integers: gcd(a,b) = gcd(b,a mod b), with gcd(a,0) = |a|. LCM(a,b) = (|a| / GCD(a,b)) × |b|.

Step by step

For 48 and 18: 48 mod 18 = 12; 18 mod 12 = 6; 12 mod 6 = 0. Therefore GCD = 6. Then LCM = (48 / 6) × 18 = 144. Check: 6 × 144 = 48 × 18 = 864.

Detailed calculation guide

The greatest common divisor (GCD), also called the highest common factor (HCF), is the largest positive integer that divides both nonzero inputs without a remainder. The least common multiple (LCM) of two nonzero integers is the smallest positive integer divisible by both. These solve different problems: GCD is useful for simplifying fractions or splitting quantities into equal groups; LCM is useful for finding a common denominator or a repeating interval.

For 48 and 18, Euclidean division produces the remainders 12, 6 and 0. The last nonzero remainder is 6, so the GCD is 6. Dividing before multiplying gives the LCM as (48 / 6) × 18 = 144. The relationship GCD(a,b) × LCM(a,b) = |a × b| provides a useful cross-check for nonzero inputs.

The Euclidean algorithm repeatedly replaces a pair (a,b) with (b,a mod b). A common divisor of a and b also divides their remainder; this preserves the common divisors until a remainder of zero is reached. The remaining nonzero value is the GCD. You do not need to list every factor, which makes this method practical for larger integers.

This tool accepts signed whole integers and calculates using their absolute values. For example, -48 and 18 return the same nonnegative GCD and LCM as 48 and 18. Leading zeros and an optional plus sign are accepted. Decimals, fractional expressions, commas and scientific notation are rejected so that the exact integer you intended is unambiguous.

Zero needs a stated convention. For a nonzero integer a, this tool returns GCD(a,0) = |a| and uses the computational convention LCM(a,0) = 0. Zero is not a positive common multiple. For two zero inputs, the tool displays an explanatory error rather than presenting a numerical answer as a uniquely defined greatest divisor.

Inputs may contain up to 80 decimal digits each. Results remain exact and may be longer than either input. This is a two-integer calculator; it does not calculate percentages or accept a list of unrelated quantities. For a list of nonzero integers, apply the two-input GCD or LCM repeatedly, using the previous result and the next integer.

To simplify a fraction 48/18, divide numerator and denominator by GCD(48,18) = 6 to obtain 8/3. To combine intervals of 12 and 18 units, their first positive common interval is LCM(12,18) = 36 units. The units must represent the same kind of interval; the mathematical result alone does not establish that real schedules or events recur exactly.

GCD and LCM of 48 and 18

GCD 6; LCM 144

Euclidean remainders are 12, 6 and 0; the last nonzero remainder is 6. (48 / 6) × 18 = 144.

Coprime integers

GCD 1; LCM 221

13 and 17 share no positive divisor larger than 1, and their product is 221.

Negative input

GCD 6; LCM 144

The tool calculates using the absolute values 48 and 18.

One zero input

GCD 18; LCM 0

The nonzero absolute input is the GCD; this tool explicitly uses the computational zero-LCM convention.

Frequently asked questions

Are GCD and HCF the same?

Yes. Greatest common divisor and highest common factor describe the same positive divisor for the nonzero inputs considered here.

Can I enter decimals?

This tool accepts whole integers only. Decimals and fractional expressions require a separately defined problem and are rejected.

What happens with two zeros?

This tool reports that the result is not defined instead of returning a misleading uniquely greatest divisor.

Browse all calculators in this category

Editorial review

Author: JD

Sources

Enable JavaScript to use interactive calculators.