MathorynMathematical Formula Database

Number Theory

Euclidean Algorithm

The Euclidean algorithm finds the greatest common divisor by repeatedly replacing the larger number with the remainder of the division, until the remainder is zero.

gcd⁡(a,b)=gcd⁡(b, a mod b),gcd⁡(a,0)=a\gcd(a,b)=\gcd(b,\ a\bmod b),\qquad \gcd(a,0)=a
LaTeX\gcd(a,b)=\gcd(b,\ a\bmod b),\qquad \gcd(a,0)=a

Variables

a mod ba\bmod b
remainder when a is divided by b

Example

Find gcd⁡(252,105)\gcd(252,105).

  1. 252=2⋅105+42252=2\cdot105+42.
  2. 105=2⋅42+21105=2\cdot42+21.
  3. 42=2⋅21+042=2\cdot21+0.

Answer: gcd⁡=21\gcd=21.

Related formulas