GCD, LCM & the Euclidean Algorithm

Master the oldest algorithm in mathematics: computing GCD through repeated division and Bézout's identity

The Oldest Algorithm

Euclid's 2,300-year-old recipe for the greatest common divisor is still in daily use. Watch it tile rectangles, solve equations, and count points on a grid.

Euclidean Algorithm Visualizer

Pick two numbers and step through the divisions. The rectangle fills with squares, and the smallest square that fits is the GCD.

Euclidean Algorithm Stepper

Stepa=q × b+r
1252=2 × 105+42
2105=2 × 42+21
342=2 × 21+0

Rectangle Tiling

Go deeper:Euclidean Algorithm Visualizer

The Euclidean algorithm, described by Euclid around 300 BC, is the oldest known algorithm still in widespread use. It computes the greatest common divisor (GCD) of two integers through repeated division — and it has a beautiful geometric interpretation.

Beyond computing GCD, the extended Euclidean algorithm finds integers x and y satisfying ax + by = gcd(a, b) (Bézout's identity). This result is foundational for modular arithmetic, cryptography, and Diophantine equations.

Watch the algorithm in action: at each step, divide the larger number by the smaller, keep the remainder, and repeat. The geometric interpretation shows this as tiling a rectangle with squares — the GCD is the side length of the smallest square that tiles the original rectangle.

Bézout's Identity Finder

Step through the forward pass to the GCD, then watch back-substitution find x and y with ax + by = gcd(a, b).

Bézout Identity Finder

Forward pass

Euclidean Algorithm

StepEquation
1240 = 5 × 46 + 10
246 = 4 × 10 + 6
310 = 1 × 6 + 4
46 = 1 × 4 + 2
54 = 2 × 2 + 0
Go deeper:Bézout's Identity Finder

The extended Euclidean algorithm goes further: it finds integers x and y such that ax + by = gcd(a, b). Watch the forward pass compute the GCD, then the back-substitution recover the Bézout coefficients.

GCD and LCM Relationship

Slide the two numbers and compare their prime factors: GCD keeps the smaller power of each prime, LCM the larger.

GCD & LCM Relationship

36 = 2^2 × 3^2
48 = 2^4 × 3
Only a
--
Shared (GCD)
2^23
Only b
--

gcd(36, 48)

12

lcm(36, 48)

144

gcd(36, 48) × lcm(36, 48) = 12 × 144 = 1728

36 × 48 = 1728

Verified: gcd(a,b) × lcm(a,b) = a × b

Go deeper:GCD and LCM Relationship

The GCD and LCM are two sides of the same coin. Through prime factorizations, GCD takes the minimum exponent of each prime while LCM takes the maximum. Together they satisfy the beautiful identity: gcd(a,b) × lcm(a,b) = a × b.

GCD as Lattice Points

Drag the endpoint of the segment from (0,0). Count the grid points it passes through: always gcd(a,b) + 1.

GCD & Lattice Points

gcd(12, 8) = 4
Lattice points on line = 5

The number of lattice points on the segment from (0,0) to (a,b), including endpoints, equals gcd(a,b) + 1. Drag the orange endpoint to move it.

0055101015152020(0,0)(12,8)
Go deeper:GCD as Lattice Points

Here's a surprising geometric fact: draw a line segment from (0,0) to (a,b) on an integer grid. The number of lattice points on the segment (including endpoints) is exactly gcd(a,b) + 1. Drag the endpoint to explore!

Key Takeaways

  • The Euclidean algorithm and its geometric rectangle-tiling interpretation
  • Bézout's identity and the extended Euclidean algorithm
  • The deep connection between GCD and LCM through prime factorizations
  • The geometric meaning of GCD as lattice point counting

Spot a mistake or have an idea?

Search