GCD & LCM Calculator
Find Greatest Common Divisor and Least Common Multiple of multiple numbers. Show step-by-step factorization.
What are GCD and LCM?
GCD (Greatest Common Divisor, also called HCF – Highest Common Factor) is the largest positive integer that divides all input numbers without leaving a remainder. LCM (Least Common Multiple) is the smallest positive integer that all input numbers divide into without remainder. Both are foundational concepts in number theory taught in elementary school but used throughout life: simplifying fractions (divide numerator and denominator by their GCD), finding common timing patterns (LCM of schedules), cryptography (RSA encryption uses GCD), and music theory (rhythm patterns rely on LCM). Understanding these helps with practical problems like ‘how often do two trains depart together?’ or ‘what’s the smallest cake to feed 6, 8, or 12 guests evenly?’
How to use this tool
- Enter numbers — Comma-separated positive integers. Minimum 2 numbers, no maximum.
- Read GCD and LCM — Both calculated instantly. Also shows sum, product, and unique stats.
- Study prime factorizations — Each input number is shown broken down into prime factors – this is how GCD/LCM are mathematically computed.
GCD and LCM mathematics
GCD (Euclidean algorithm):
GCD(a, b) = GCD(b, a mod b) until b = 0. The non-zero number left is the GCD.
For 12 and 18:
- GCD(12, 18) = GCD(18, 12 mod 18) – but 12 < 18, so we use GCD(18, 12) = GCD(12, 18 mod 12) = GCD(12, 6) = GCD(6, 0) = 6
LCM formula:
LCM(a, b) = (a × b) / GCD(a, b)
For 12 and 18: LCM = (12 × 18) / 6 = 216 / 6 = 36
Key relationship: GCD(a,b) × LCM(a,b) = a × b
Prime factorization approach:
For GCD: take MINIMUM exponent of each prime appearing in ALL numbers.
For LCM: take MAXIMUM exponent of each prime appearing in ANY number.
12 = 2² × 3¹
18 = 2¹ × 3²
GCD: 2¹ × 3¹ = 6 (min exponents)
LCM: 2² × 3² = 36 (max exponents)
Examples
- GCD(8, 12, 16) = 4, LCM(8, 12, 16) = 48
- GCD(15, 25) = 5, LCM(15, 25) = 75
- GCD(7, 11) = 1 (coprime), LCM = 77
- GCD(36, 60) = 12, LCM = 180
- Two trains: One leaves every 12 mins, another every 18 mins. They depart together every LCM(12,18) = 36 mins
- Cake feeding 6 or 8 people: Smallest size feeding both evenly = LCM(6,8) = 24 slices
- Simplifying 36/60: Divide both by GCD = 12, gives 3/5 (simplest form)
Tips & best practices
- GCD(a,b) = 1 means numbers are ‘coprime’ (share no common factors). Used in cryptography (RSA)
- LCM >= max(a,b) always – LCM can never be smaller than the largest input number
- If one number is a multiple of another, GCD = smaller number, LCM = larger number
- Use Euclidean algorithm for fast computation – much faster than checking all divisors
- For 3+ numbers: GCD(a,b,c) = GCD(GCD(a,b), c). Same for LCM. Reduce pairwise
- Simplifying fractions: 56/72 → GCD = 8 → 56/8 ÷ 72/8 = 7/9. Always simplify fractions
- Cryptography uses GCD computations on huge numbers (RSA keys hundreds of digits) – computers do this efficiently
Limitations & notes
Calculator works with positive integers only. Negative numbers and zero have undefined or trivial GCD/LCM. For very large numbers (over 10^15), JavaScript precision limits accuracy. For polynomial GCDs or other algebraic structures (matrices, finite fields), specialized math software is needed.
Frequently Asked Questions
What’s the difference between GCD and HCF?
Same thing, different terminology. GCD (Greatest Common Divisor) is the US term. HCF (Highest Common Factor) is the British/Indian term used in schools. Both refer to the largest number that divides all inputs evenly. Use whichever your textbook uses.
Can GCD be larger than the smallest number?
No – GCD must divide ALL inputs evenly. The smallest input is the upper bound for GCD. Often GCD is much smaller (or 1, if numbers are coprime).
Why is GCD useful?
Simplifying fractions (divide num and denom by GCD), reducing ratios to simplest form, cryptographic algorithms (RSA encryption), efficient algorithms (Euclidean algorithm is foundational), abstract algebra and number theory.
When do I use LCM in real life?
Schedule synchronization (two events repeating at different intervals coincide every LCM cycles), planning portions evenly divisible (cake for 6 or 8 guests = LCM=24), gear ratios in machinery, music rhythms (when polyrhythms align), traffic light timing optimization.
What if all my numbers are coprime?
GCD = 1 (numbers share no common factors). LCM = product of all numbers (no reduction possible). For example: GCD(5,7,11) = 1, LCM(5,7,11) = 385.
How do I find GCD of 3 or more numbers?
Pairwise. GCD(a,b,c) = GCD(GCD(a,b), c). So GCD(12,18,24) = GCD(GCD(12,18), 24) = GCD(6,24) = 6. Same approach for LCM.
What is prime factorization?
Breaking a number into prime factors. 12 = 2 x 2 x 3 = 2² x 3. 18 = 2 x 3². Every integer > 1 has a unique prime factorization (Fundamental Theorem of Arithmetic). This factorization makes GCD/LCM computation straightforward.
Related tools
Quadratic Equation Solver · Statistics Calculator · Percentage Calculator
