Skip to main content

๐Ÿ”ข GCD & LCM Calculator

Calculate GCD and LCM using the Euclidean algorithm

GCD(24, 36)
12
Euclidean Algorithm
LCM(24, 36)
72
aร—bรทGCD
Calculation Process
Input: a = 24, b = 36
GCD(24, 36) = 12
LCM(24, 36) = 24 ร— 36 รท 12 = 72
Verification: 12 ร— 72 = 864 = 24 ร— 36 = 864

GCD & LCM Calculator Guide

This tool uses the efficient Euclidean algorithm to calculate the Greatest Common Divisor (GCD) and Least Common Multiple (LCM) of two positive integers. Simply enter two positive integers to get both GCD and LCM values, along with a complete calculation process.

The GCD is the largest positive integer that divides all given numbers. The LCM is the smallest positive integer divisible by all given numbers. These two concepts are widely used in number theory, cryptography, fraction simplification, and other fields, and are fundamental topics in elementary mathematics.

Core Formulas and Algorithm

ใ€Euclidean Algorithm for GCDใ€‘
gcd(a,b):
  while b โ‰  0:
    t = b
    b = a mod b
    a = t
  return a

ใ€GCD-LCM Relationshipใ€‘
LCM(a,b) = |a ร— b| / GCD(a,b)

Important property: GCD(a,b) ร— LCM(a,b) = a ร— b

Practical Examples

๐Ÿ“‹
ใ€Example 1ใ€‘Find GCD and LCM of 24 and 36 Euclidean algorithm: 36 รท 24 = 1 remainder 12 24 รท 12 = 2 remainder 0 When remainder is 0, GCD = 12 LCM = 24 ร— 36 รท 12 = 72 ใ€Example 2ใ€‘Find GCD and LCM of 15 and 28 Euclidean algorithm: 28 รท 15 = 1 remainder 13 15 รท 13 = 1 remainder 2 13 รท 2 = 6 remainder 1 2 รท 1 = 2 remainder 0 GCD = 1 (coprime) LCM = 15 ร— 28 รท 1 = 420 ใ€Example 3ใ€‘Use GCD/LCM for fraction addition GCD(12,18)=6, LCM(12,18)=36 5/12 + 7/18 = 15/36 + 14/36 = 29/36

Important Notes

๐Ÿ’ก
- Input must be positive integers; 0 and negative numbers are not supported (GCD is defined for natural numbers) - When two numbers are coprime (e.g., 15 and 28), GCD=1, LCM equals the product of the two numbers - The Euclidean algorithm has time complexity O(log min(a,b)), extremely fast even for large numbers - For three or more numbers, compute GCD of the first two, then continue with the third - The GCD of prime numbers is always 1 (unless the two numbers are the same)

Application Scenarios

  • - Fraction operations: Find LCM as common denominator for addition, find GCD for simplification
  • - Scheduling: Find the minimum common interval for recurring events (e.g., shift rotation design)
  • - Cryptography: RSA encryption relies on large number factorization and GCD computation
  • - Gear design: Calculate minimum teeth for precise gear ratio transmission
  • - Music theory: Calculate beat frequency ratios, interval harmony analysis

Relationship with Related Tools

The GCD/LCM calculator works closely with the fraction calculator โ€” fraction addition requires common denominators (using LCM), and results need simplification (using GCD). Permutation and combination calculations also frequently involve GCD, such as simplifying combination number C(n,k) results. Additionally, GCD is a fundamental tool in solving Diophantine equations, determining coprimality, and the Chinese Remainder Theorem. Mastering GCD/LCM calculation is the first step toward understanding number theory.

Ad Slot