Previous: Chinese Remainder Theorem, Next: Modular ArithmeticUp: Number Theory

Euclid's Algorithm

Table of Contents

1. Diophantine Equations

Let a,b and c be fixed integers, then consider integer solutions to the equation:

(1)ax+by=c

We show there exist solutions iff gcd(a,b)|c, and further, if this is the case then there are an infinite number of solutions.

1.1. Lemma 1

if gcd(a,b)c There exists no solution to (1).

Proof:

Suppose for a contradiction there does exist a solution, and let p=gcd(a,b)

λ,δZ  s.t. a=λp, b=δp

Factoring (1):

(λx+δy)p=c

Which shows p must divide c and hence is a contradiction.

1.2. Lemma 2

There exists a solution to (1) if c=gcd(a,b)

Proof:

We have

gcd(a,b)pmodb

Then a solution exists to (1) iff there exists some x s.t.

(2)axpmodb

First, note that λ and δ are coprime, proof: consider

gcd(λp, δp)

If gcd(λ,δ)>1gcd(a,b)p and hence is a contradiction.

It's commonly known that since λ and δ are coprime, there exists an integer x s.t.

λx1modδ

And hence this x is a solution to:

p(λx1)0modb

Rearranging:

axpmodb

And therefore:

ax+by=gcd(a,b)

Where y is axb. Hence trivially there also exists a solution for any integer multiple of gcd(a, b).

1.3. Lemma 3

If there exists one solution to ax+by=c then there exists infinite solutions.

Proof:

Consider solutions to:

(3)kaa+kbb=0

Setting ka=lcm(a,b)a and kb=lcm(a,b)b gives a solution to (3). Also note that:

(x+ka)a+(y+kb)b=c

Is also a solution given x, y are the solutions found above, and furthermore:

(x+Mka)a+(y+Mkb)b=c

Where M is any integer, is a solution.

2. Euclid's Algorithm

We can express gcd(a,b) as a linear combination of a and b easily using Euclid's algorithm.

2.1. Example

Express gcd(1442, 980) as a linear combination of 1442 and 980.

First we obtain gcd(1442, 980) using Euclid's algorithm:

(4)1442=1980+462(5)980=2462+56(6)462=856+14(7)56=414

Hence gcd(1442, 980) = 14. Now we take the penultimate equation and rearrange to make 14 the subject:

(8)14=462856(9)14=(1442980)8(9802462)(10)14=114429980+16(1442980)(11)14=17144225980

And thus we arrive at the linear combination.

Author: root

Created: 2025-02-15 Sat 15:26

Validate