Mathematics
GCD and LCM calculator
Type the numbers separated by commas: you get the greatest common divisor and the least common multiple together with the prime factorization they are read off, which is the working the exercise asks you to show.
What GCD and LCM are, and when you need them
The greatest common divisor is the largest number that divides all the given ones exactly; the least common multiple is the smallest number that contains them all a whole number of times. They are two faces of the same factorization: once every number is written as a product of prime powers, the GCD takes the shared factors with the smaller exponent and the LCM takes every factor with the larger exponent.
They answer different questions. The GCD handles division: what is the largest square tile that exactly fills a 120 × 90 cm room, into how many equal groups can a class be split. The LCM handles synchronisation: how many days until two shifts repeating every 6 and every 8 days fall together, what common denominator lets two fractions be added.
For just two numbers Euclid's algorithm is faster than factorizing, and it does not require finding any primes: divide the larger by the smaller, then the divisor by the remainder, and so on until the remainder vanishes. The last non-zero divisor is the GCD. The LCM follows immediately, because for two numbers GCD × LCM = a × b always holds.
Common mistakes
- Swapping the exponent rules: the GCD takes shared factors with the smallest exponent, the LCM takes every factor with the largest. Reversing them gives two plausible, wrong numbers.
- Dropping the non-shared factors from the LCM: if one number contains a prime the others lack, that prime still belongs in the least common multiple.
- Using GCD × LCM = a × b with more than two numbers: it holds only for a pair. With three numbers the product of the two results bears no fixed relation to the product of the inputs.
Frequently asked questions
How do you find the GCD using prime factorization?
Factorize each number, find the primes present in every factorization, and multiply them taking the lowest exponent for each. For 12 = 2²·3 and 18 = 2·3² the shared factors are 2 and 3 with minimum exponents 1 and 1, so the GCD is 6.
And the least common multiple?
Take every prime that appears in at least one factorization, each with the highest exponent it reaches. For 12 = 2²·3 and 18 = 2·3² you take 2² and 3², so the LCM is 36.
What does it mean for two numbers to be coprime?
That their GCD is 1, so they share no prime factor. It does not mean they are prime numbers: 8 and 9 are coprime although both are composite. In that case the LCM equals the product.
What is the LCM used for with fractions?
It is the smallest common denominator for adding or comparing two fractions. Using the product of the denominators always works but produces larger numbers to simplify afterwards.
How this calculation works
Factorization: every integer greater than 1 can be written uniquely as a product of prime powers (fundamental theorem of arithmetic). GCD: the product of the primes shared by all factorizations, each with its minimum exponent. LCM: the product of every prime that appears, each with its maximum exponent. Euclid's algorithm: GCD(a; b) = GCD(b; a mod b), repeated until the remainder is zero. Relation between the two, valid for a pair: GCD(a; b) × LCM(a; b) = a × b. For more numbers the LCM is built pairwise: LCM(a; b; c) = LCM(LCM(a; b); c).
Related calculators
Percentages
Percentage of a total, increases, discounts, percentage change and reverse percentage.
Fractions
Addition, subtraction, multiplication and division of fractions, reduced to lowest terms.
Proportions
Missing term, fourth proportional, geometric mean and third proportional.
Prime factorisation
Prime factors of a number up to 30 digits, with the division ladder, divisors and a primality test.