PAIBOTLearn
Sign inSign up

Euclidean algorithm

Number theory basics

Japanese school year: Math A

What you learn

You will learn an efficient algorithm to find the greatest common divisor of two integers using division remainders. It is especially useful when dealing with large numbers that are hard to factor. Familiarity with the division algorithm and properties of integer remainders is helpful before learning this.

Go to practice

Key points

This formula represents integer division. When an integer aa is divided by a positive integer bb, qq is the quotient and rr is the remainder, satisfying 0≤r<b0 \le r < b.

a=bq+r(0≤r<b)a = bq + r \quad (0 \le r < b)

Use this formula to efficiently find the GCD of large numbers. The GCD of aa and bb equals the GCD of the divisor bb and the remainder rr.

gcd⁡(a,b)=gcd⁡(b,r)\gcd(a, b) = \gcd(b, r)

This equation shows that there exist integers xx and yy satisfying this relationship. You can find a specific solution pair (x,y)(x, y) by tracing the Euclidean algorithm backward.

ax+by=gcd⁡(a,b)ax + by = \gcd(a, b)

Choose a set to practice.