Greatest Common Divisor

S2: Divisibility

For the purposes of the following definitions and lemmas, U=Z (including negatives):

Divisibility

a|b (when a≠0) if ∃x such that b=ax. We say a divides b. If a cannot divide b then we write a∤b.

If 0<a<b then a is a proper divisor of b. It is best understood that a≠0 for (pretty much) all of these cases. Further:

  • 0|x is always FALSE (undefined when x=0)
  • x|0 is always TRUE (for all x)

One interesting thing is that the notation aK||b is sometimes used to indicate aK|b∧aK+1∤b.

Properties of Divisibility

  1. a|b implies a|bc ∀c
  2. a|b and b|c implies a|c
  3. a|b and a|c implies a|(bx+cy) for all x,y
  4. a|b and b|a implies a=±b
  5. a|b when a,b>0 implies a≤b
  6. If m≠0 then a|b iff ma|mb

Proof
(1): If a|b then ∃x where b=ax. Let c be arbitrary. Then multiply both sides to get bc=axc. Let x′=xc. Then bc=ax′ so by definition then a|bc as required.

(2): If a|b and b|c then ∃x,y where b=ax and c=by. Substitute the first into second equation to get c=(ax)y=a(xy). Since xy is an integer then by definition then a|c.

(3): If we prove that a|b,a|c implies a|(b+c) then we are done (just use (1) after that). Let a|b,a|c, so then b=ax and c=ay. Add both together to get b+c=a(x+y). Clearly x+y is an integer so then a|(b+c).

Using this, then a|b,a|c implies that a|bx and a|cy for any x,y. Therefore, using our lemma then a|(bx+cy) and we are done.

(4): If a|b,b|a then b=ax and a=by. Substitute the left into the right to get that a=(ax)y=a(xy). Dividing by a gives that 1=xy. The only two cases are that x,y=1 or x,y=−1. If x,y=1 then a=b(1)=b and in the other case a=b(−1)=−b so in either case we have a=±b as expected.

(5): If a|b and a,b>0 then ∃x where b=ax. Since b>0 and a>0 we require that x>0. We can therefore use induction over x:

  • If x=1 then a=b satisfied a=ax≤b.
  • Suppose the x case has it that a≤ax≤b. If we consider x+1 then:
    b=a(x+1)≥ax≥a
    In all cases we have a≤b as expected.

(6): Suppose m≠0. a|b iff ∃x where b=ax iff mb=max iff (mb)=(ma)x iff mb|ma.
☐
Notice that this extends for all linear combinations of integers too:
a|b1,a|b2,...,a|bn⇒a|∑j=1nbjxj∀xj∈Z
Property 2 can be extended similarly:
a1|a2,a2|a3,...,an−1|an⇒a1|an

Using these properties:

  1. 6|18 so with c=2 that implies that 6|36. Multiplication can only add factors.
  2. 6|18 and 18|180 so then 6|180. A 'divisibility chain' can only really add factors the farther you go.
  3. Comes from the fact that factors distribute on addition. If 6|12 and 6|6 then 6|12+6 because we can take the same factor from both and 'divide' them out.
  4. If a|b and b|a then ba and ab are integers, so clearly they have to equal ±1.
  5. If a|b then when a,b>0 then ba≥0 so clearly a≤b as a result (when a≠0)
  6. Comes from just multiplying fractions on the top and bottom by the same factor.

Division Algorithm

Given any integers a,b∈Z with a>0 then !∃q,r∈Z such that:
b=qa+r
where 0≤r<|a|. In the case a∤b then r satisfies the strong inequalities 0<r<|a|.

Proof
Consider the arithmetic progression:
…,b−3a,b−2a,b−a,b,b+a,b+2a,b+3a,…
In this sequence, select the smallest non-negative member and denote it by r. Thus by definition r satisfies the inequalities of the theorem. But also r being in the sequence is of the form b−qa and thus q is defined in terms of r.

To show uniqueness, suppose q1,r1 are other integers that satisfy the algorithm. First we prove r1=r. Suppose not, so then we can say that r<r1 (WLOG) so then 0<r1−r<a. See that r1−r=a(q−q1) (by plugging in b=q1a+r1=qa+r, so then a|(r1−r). This contradicts Properties of Divisibility, since then (using property 3) we have a|r1 and a|r which is impossible by the inequalities we imposed. Thus r=r1 and consequently q=q1 by plugging into the DA equation.

For the consideration when a<0, just restate the theorem to use |a| instead, and we get similar results.
☐

Why call it an algorithm?

Even though the theorem above shows an algorithm to find q,r, something like a computer would do the arithmetic by hand to find both. Really, the theorem helps show the existence of q,r and their uniqueness, rather than a 'good' algorithm for it.

A good way to get these number is just to divide normally, then get the quotient and find r=b−qa:
6113=?⇒13)61―=4R9⇒q=4,r=9⇒61=13⋅4+9

Greatest Common Divisor (GCD)

a is a common divisor of b and c in case a|b and a|c.

There are only a finite number of divisors of any non-zero integer, so there is only a finite number of common divisors of b,c except in the case b=c=0. If at least one of b and c is not 0, the greatest among their common divisors is called the greatest common divisor of b and c and is denoted either (b,c) or gcd(b,c). Similarly, we denote the greatest common divisor g of the integers b1,...,bn not all zero by (b1,...,bn)=gcd(b1,...,bn).

We note that gcd(b,c)≥1 for all b,c≠0.

Linear combination of GCD

If g=gcd(b,c) then ∃x0,y0 such that g=gcd(b,c)=bx0+cy0

Proof
Consider the linear combinations bx+cy, where x,y range over all the integers. Clearly then:
S={bx+cy|x,y∈Z}={⋯,−x−y,−x,−x+y,⋯,−y,0,y,⋯,x−y,x,x+y,⋯}
Clearly 0 is in the set with x=y=0. Now, choose x0,y0 such that bx0+cy0 is the least positive integer l in this set (we can do this by the well-ordering principle). Thus l=bx0+cy0.

Next we prove l|b,l|c. Doing the first shows the second by analogy. Proving l|b, by contradiction assume that l∤b. Using our Division Algorithm then !∃q,r such that b=lq+r where 0<r<l (notice the stricter inequality here). Therefore then we have r=b−lq=b−q(bx0+cy0)=b(1−qx0)+c(−qy0). Notice the form of the equation, it allows us to put r∈S. But this contradicts the fact that l is the least positive integer in the set S (since r would be the least positive integer instead). By contradiction then l|b. Similarly, l|c.

Since g is the greatest common divisor of b,c we may write b=gB and c=gC and:
l=bx0+cy0=gBx0+gCy0=g(Bx0+Cy0)
Thus clearly then g|l and so by part 5 of Property 5 then g≤l. Now g<l is impossible since g is the greatest common divisor, so clearly g=l=bx0+cy0.
☐

Using Linear combination of GCD

For instance, if we have it that gcd(180,282)=6 then 6=180x0+282y0 has the solution x0=11 and y0=−7:
6=180(11)+282(−7)=1980−1974
Notice the proof itself doesn't really show how to find these x0,y0 values. We'll see that later in Euclid's Algorithm.

Properties of the GCD

The GCD g=gcd(b,c) can be characterized as:

  1. g is the least positive value of bx+cy where x,y range over all Z
  2. It is the positive common divisor of b and c that is divisible by every common divisor.

Proof
(1): Use our linear combination argument, this is the smallest by the argument for the proof (we used the smallest element).

(2): If d is any common divisor of b and c then d|g by Property 3 of the properties of divisibility. Property 4 further restricts only one set of integers with this property.
☐
Clearly if any divisor d of the form d=bx+cy then d is not necessarily gcd(b,c) (ie: the converse isn't necessarily true).

Generalization of Linear Combinations of GCD

Given integers b1,...,bn, not all zero, with greatest common divisor g, ∃x1,...,xn∈Z such that:
g=gcd(b1,...,bn)=∑j=1nbjxj
Furthermore g is the least positive value of the linear form ∑j=1nbjyj where all yj range over Z. Also g is the positive common divisor of b1,...,bn that is divisible by every common divisor.

Proof
Use induction over n, using the same argument for n=2 case.
☐

Extending GCD for known multiples m

For any m∈Z+:
gcd(ma,mb)=mgcd(a,b)

Proof
By properties of the GCD, we have:
gcd(ma,mb)=least positive value of max+mby=m⋅least positive value of ax+by=m⋅gcd(a,b)
☐

GCD with internal divisors d

If d|a and d|b and d>0 then:
gcd(ad,bd)=1dgcd(a,b)
If gcd(a,b)=g then:
gcd(ag,bg)=1

Proof
(2) comes from (1) when d=gcd(a,b). Just prove (1).

(1): Use extension of GCD w/ m by replacing the following: m↔d, a↔ad, and b↔bd:
gcd(d⋅ad,d⋅bd)=dgcd(ad,bd)=gcd(a,b)
Gives the result we have above.
☐

Multiplicative Property of Coprimality

If gcd(a,m)=gcd(b,m)=1 then gcd(ab,m)=1.

Namely, if a,m are coprime and b,m are coprime, then ab is coprime with m.

Proof
Suppose gcd(a,m)=gcd(b,m)=1. Using the Linear GCD properties then ∃x0,y0,x1,y1 such that:
1=ax0+my0=bx1+my1
Rearranging:
ax0+b(−x1)=m(y1−y0)
Notice that (starting from some new equation, using the fact that ax0=1−my0 and bx1=1−my1):
(ax0)(bx1)=(1−my0)(1−my1)=1−m(y0+y1−my0y1)
Choose X0=x0x1 and Y0=y0+y1−my0y1. Then:
abX0=1−mY0⇒1=abX0+mY0
Therefore, then using Property 3 implies that any common divisor of ab and m is a divisor of 1. Therefore, then gcd(ab,m)=1.
☐

Example

If we have a=10 and b=21 and m=11 then we fill all GCD requirements. Furthermore, notice that:
gcd(ab,m)=gcd(10⋅21,11)=gcd(210,11)=1
This makes sense. We're essentially saying that if the primes of a,b and m don't match up, then combining the primes into ab doesn't change the fact that they don't share prime factors with m still.

Relative Primes

We say a,b are relatively prime when gcd(a,b)=1. a1,...,an are all relatively prime when gcd(a1,...,an)=1. We say they are relatively prime in pairs in case gcd(ai,aj)=1 for all i,j=1,...,n when i≠j.

GCD Equivalences

For any x∈Z, the following are equivalent:

  1. gcd(a,b)
  2. gcd(b,a)
  3. gcd(a,−b)
  4. gcd(a,b+ax)

Proof
Clearly (1) → (2) by reordering our integers appropriately. Similarly, we can go from (1) → (3) by just realizing that when we have gcd(a,b)=d=ax0+by0=ax0+(−b)(−y0)=gcd(a,−b).

Start at (1) and we'll go to (4). Say g=gcd(a,b)=d. We know there ∃x0,y0 such that:
d=ax0+by0
Then:
d=a(x0−xy0)+(b+ax)y0
By just rearranging terms. It follows that the GCD of a and b+ax is a divisor of d, namely g|d. If we can prove that d|g then we are done and have shown d=±g and since both are positive then d=g (see Property 5).

Since d|a and d|b then d|(b+ax) from Property 3. We know also from GCD Property 2 that every common divisor of a and b+ax is a divisor of their GCD, namely it's a divisor of g. Hence d|g.
☐

Example

It's pretty easy to see the first 3 as being equivalent, but what about (4)? Say a=180,b=240 so then g=gcd(a,b)=60. Then:
gcd(180,240+180x)=60
Is pretty clear. That's because we could take a factor of 60 from the inside (see Mult. Property) to get:
60=60gcd(3,4+3x)
Where the GCD portion of course becomes 1 since the 3x part will make sure that the 4 which is 1mod3 will never have that remainder be 0.

GCD to Divisibility Argument

If c|ab and gcd(b,c)=1 then c|a.

Proof
Using Extension with m=a via:
gcd(ab,ac)=agcd(b,c)=a
Since we suppose that c|ab and obviously c|ac. Then c|a because of Property 2 in conjunction with the equation above (c is a divisor of both ab and ac and since gcd(ab,ac)=a then c|a as a result via the property)
☐

Solving Linear Diophantine Equations

Given two integers b,c, how can the GCD g be found? This is hard especially for large b,c, and canning the range of $bx_{0} + cy_{0}s would take forever (literally).

But we can use GCD Equivalences to help us find the GCD, as well as our values of x0,y0 (for solutions to our linear equations).

Consider b=963,c=657. If we divide c into b we get q=1 and remainder r=306. Thus:
b=cq+r⇔r=b−cq
In particular;
306=963−1⋅657
Now using our GCD Equivalences, we know:
gcd(b,c)=gcd(b−cq,c)
By using a=c and x=−q in the 4th equivalence in the list (and the first ↔ second of course). Thus:
gcd(963,657)=gcd(963−1⋅657,657)=gcd(306,657)
We've made our integers smaller! The procedure can be repeated again where now q=2,r=45:
=gcd(306,657−2⋅306)=gcd(306,45)
Next q=6,r=36:
=gcd(306−6⋅45,45)=gcd(36,45)=gcd(36,9)=9
Thus gcd(963,657)=9. With this result we can write the result as a linear equation:
306=963−65745=657−2⋅306=657−2(963−657)=3⋅657−2⋅96336=306−6⋅45=(963−657)−6⋅(3⋅657−2⋅963)=963−657−18⋅657+12⋅963=−19⋅657+13⋅9639=45−1⋅36=(3⋅657−2⋅963)−1⋅(−19⋅657+13⋅963)=22⋅657−15⋅963
So for the solution to g=gcd(a,b)=ax0+by0 in this case, then g=9 with x0=−15 and y0=22.

Note

The values of x0,y0 are not unique. In fact in this case x0=−15+657k and y0=22−963k are all valid solutions (k∈Z).

Let's generalize the process:

Euclidean Algorithm

Given integers b,c>0 we make a repeated application of the division algorithm:
b=cq1+r10<r1<cc=r1q2+r20<r2<r1r1=r2q3+r30<r3<r2⋮rj−2=rj−1qj+rj0<rj<rj−1rj−1=rjqj+1
The gcd(b,c) is rj, the last non-zero remainder in the division process. Values of x0,y0 where gcd(b,c)=bx0+cy0 are obtained by writing each ri as a linear combination of b and c and working your way up.

Proof
The chain of equations is obtained by dividing c into b, r1 into c, r2 into r1, ..., rj into rj−1. The process stops when the new remainder is 0. Thus in our application of 1 - Divisibility#^344c2e we have written the inequalities for the remainder without an equality sign:
0<r1<c
And we stop at the point where we'd use ≤ instead, so then clearly:
0<rj<rj−1<⋯<r1<c
We'll use this to prove that rj is the GCD of (b,c). By 1 - Divisibility#^acc042, we observe that:
gcd(b,c)=(b−cq1,c)=gcd(r1,c)=gcd(r1,c−r1q2)=gcd(r1,r2)=…
Continuing by mathematical induction we get that:
gcd(b,c)=gcd(r1,r2)=⋯=gcd(rj−1,rj)=gcd(rj,0)=rj
For showing rj as a linear combination, we argue by induction that each ri is a linear combination of b,c. Clearly r1 is such a linear combination, and so is r2, ... so each ri is a linear combination of ri−1 and ri−2. By the inductive hypothesis we may suppose that these latter two numbers are linear combinations of b,c so it follows that ri is.
☐
An example of using the algorithm is:

2

Question

Find gcd(1819,3587)=g then find integers x,y that satisfy:
1819x+3587y=g

Proof
For finding gcd:
3587=1819⋅1+17681819=1768⋅1+511768=51⋅34+3451=34⋅1+1734=17⋅2+0
So gcd(1819,3587)=17. Solving where b=1819,c=3587:
1819x+3587y=17
1768=c−1⋅b51=b−1⋅(c−b)=2b−c34=1768−34(51)=c−b−34(2b−c)=−69b+35c17=51−1(34)=2b−c−1(−69b+35c)=71b−36c
Therefore comparing the two:
17=1819(71⏟x0)+3587(−36⏟y0)
☐

Least-common Multiple

The integers a1,...,an (all different from zero) have a common multiple b if ai|b for i=1,2,...,n (note that LCM's always exist, ex: a1a2...an). The least of the positive common multiples is called the least common multiple and is denoted:
[a1,...,an]

LCM Equivalances

If b is any common multiple of a1,...,an then [a1,...,an]|b. This is the same as saying that if h denotes [a1,...,an] then 0,±h,±2h,... comprise all the common multiples of a1,...,an

Proof
Let m be any common multiple and divide m by h. Via 1 - Divisibility^78dbe0, there is a quotient q and a remainder r such that m=qh+r where 0≤r<h. We must prove that r=0. Assume r≠0. For each i=1,2,...,n we know that ai|h and ai|m so then ai|r. Thus r is a positive common multiple of a1,...,an contrary to the fact that h is the least of all the positive common multiples.
☐

Properties of the LCM

If m>0 then [ma,mb]=m[a,b] and [a,b]⋅(a,b)=|ab|.

Proof
(1): Let H=[ma,mb] and h=[a,b]. Then mh is a multiple of ma and mb so then mh≥H. Also, H is a multiple of both ma and mb so Hm is a multiple of a and b. Thus Hm≥h so then mh=H.

(2): We'll prove just for positive integers a,b>0. Consider the special case where gcd(a,b)=1. Now [a,b] is a multiple of a, say ma. Then b|ma and (a,b)=1. Thus by 1 - Divisibility#^f558ea, then b|m. Hence b≤m and ba≤ma. But ba being positive common multiple of b and a cannot be less than the least common multiple, so ba=ma=[a,b].

In the general case when (a,b)=g>1 we have (ag,bg)=1 via internal divisors. Applying the result of the previous paragraph gives:
[ag,bg](ag,bg)=agbg
Multiplying by g2 via 1 - Divisibility#^7ef913, in combination with (1) gives us that:
[a,b](a,b)=|ab|
as desired.
☐