Evanalysis
7.1Estimated reading time: 18 min

7.1 Divisibility, gcd, and integer equations

Develop divisibility, primes, the division algorithm, Euclidean algorithm, Bezout's identity, unique prime factorization, and linear Diophantine equations.

Course contents

MATH1025: Preparatory mathematics

Preparatory mathematics notes.

9 sections

Why integer arithmetic needs new language

Integer arithmetic looks familiar, but proofs about integers need vocabulary that is more precise than ordinary division. When we write a/ba/b in real algebra, the quotient usually exists as a real number. In integer arithmetic, the important question is different: can the quotient be chosen as another integer?

This question controls many later methods. It lets us define prime numbers, measure common factors, compute greatest common divisors efficiently, and decide when an equation such as

ax+by=cax+by=c

has integer solutions.

Divisibility

Definition

Divisibility

Let a,bZa,b\in\mathbb Z. We say that a divides b, written aba\mid b, if there exists an integer d such that

b=ad.b=ad.

In that case, a is called a divisor or factor of b.

The phrase "there exists an integer" is the essential part of the definition. For example, 3153\mid 15 because 15=3515=3\cdot5, while 4154\nmid 15 because there is no integer d with 15=4d15=4d.

Several edge cases are worth fixing immediately:

  • every integer divides 0, because 0=a00=a\cdot0;
  • 0 divides only 0, because x=0dx=0\cdot d forces x=0x=0;
  • ±1\pm1 divides every integer;
  • if a0a\ne0, then both a and a-a divide a.

Theorem

Basic divisibility rules

Let a,b,cZa,b,c\in\mathbb Z.

  1. If b0b\ne0 and aba\mid b, then ab|a|\le |b|.
  2. If aba\mid b, then (±a)(±b)(\pm a)\mid(\pm b).
  3. If aba\mid b and bcb\mid c, then aca\mid c.
  4. If aba\mid b and aca\mid c, then a(bx+cy)a\mid (bx+cy) for all x,yZx,y\in\mathbb Z.

The fourth rule is the one that quietly powers much of the chapter. If a number divides two integers, then it divides every integer linear combination of them. For instance, if 6186\mid 18 and 6306\mid 30, then

618x+30y6\mid 18x+30y

for every pair of integers x,y.

Primes, composites, and well-ordering

Definition

Prime and composite

Let nZ+n\in\mathbb Z^+ with n>1n>1.

  • n is prime if its only positive divisors are 1 and n;
  • n is composite if it is not prime.

The integer 1 is neither prime nor composite.

Equivalently, n>1n>1 is composite exactly when

n=n1n2n=n_1n_2

for integers n1,n2n_1,n_2 satisfying 1<n1,n2<n1<n_1,n_2<n.

The proofs about prime numbers rely on a simple but powerful ordering fact.

Theorem

Well-ordering principle

Every nonempty subset of N={0,1,2,}\mathbb N=\{0,1,2,\ldots\} has a least element.

This principle is a way to run a least-counterexample argument. If a bad set of positive integers is nonempty, choose its least bad element and show that this least element creates an even smaller bad element. That contradiction proves that the bad set was empty.

Theorem

Every integer greater than 1 has a prime factor

Every positive integer n>1n>1 is divisible by at least one prime.

Here is the proof pattern. Suppose the claim fails, and let m be the least integer greater than 1 with no prime factor. Then m cannot itself be prime. So m=n1n2m=n_1n_2 with 1<n1,n2<m1<n_1,n_2<m. By minimality of m, the smaller number n1n_1 has a prime factor p. Since pn1p\mid n_1 and n1mn_1\mid m, transitivity gives pmp\mid m, contradicting the choice of m.

Theorem

Infinitely many primes

There are infinitely many prime numbers.

If there were only finitely many primes p1,,pNp_1,\ldots,p_N, consider

n=p1p2pN+1.n=p_1p_2\cdots p_N+1.

The previous theorem gives a prime divisor of n. That prime must be one of the listed primes, say pip_i. But pip_i also divides the product p1p2pNp_1p_2\cdots p_N, so it divides the difference

np1p2pN=1,n-p_1p_2\cdots p_N=1,

which is impossible for a prime.

Greatest common divisors

Definition

Greatest common divisor

Let a,bZa,b\in\mathbb Z. If at least one of a,b is nonzero, the greatest common divisor is

gcd(a,b)=max{dZ:da and db}.\gcd(a,b)=\max\{d\in\mathbb Z:d\mid a\text{ and }d\mid b\}.

If a=b=0a=b=0, define gcd(0,0)=0\gcd(0,0)=0.

For nonzero input, the maximum exists because the possible common divisors are bounded in absolute value. Also, gcd(a,b)\gcd(a,b) is always positive unless both inputs are zero.

Definition

Relatively prime

Two nonzero integers a and b are relatively prime if their only positive common divisor is 1. Equivalently,

gcd(a,b)=1.\gcd(a,b)=1.

The gcd removes the common part of two integers. If

d=gcd(a,b),d=\gcd(a,b),

then

gcd(ad,bd)=1.\gcd\left(\frac ad,\frac bd\right)=1.

For example, gcd(126,140)=14\gcd(126,140)=14, so

126140=910,\frac{126}{140}=\frac{9}{10},

and 9 and 10 are relatively prime.

The division algorithm

The next task is computational: how do we find the gcd without already knowing all common divisors? The key is integer division with a controlled remainder.

Theorem

Division algorithm

Let a,bZa,b\in\mathbb Z with b0b\ne0. Then there exist unique integers q and r such that

a=bq+r,0r<b.a=bq+r,\qquad 0\le r<|b|.

The integer q is the quotient and r is the remainder.

The condition 0r<b0\le r<|b| is not decoration. It is what makes the remainder unique. For example,

17=53+217=5\cdot3+2

has an allowed remainder 2, while

17=52+717=5\cdot2+7

does not count as the division algorithm because 7 is not smaller than 5.

Common mistake

Do not ignore the remainder range

The equation a=bq+ra=bq+r alone is not enough. There are infinitely many such representations if r is unrestricted, because changing q changes r. The inequality 0r<b0\le r<|b| is what selects the canonical quotient and remainder.

Gcd invariance and the Euclidean algorithm

The division algorithm is useful because replacing (a,b) by (b,r) preserves the gcd.

Theorem

Gcd step

If a=bq+ra=bq+r, then

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

Indeed, a common divisor of a and b divides r=abqr=a-bq, and a common divisor of b and r divides a=bq+ra=bq+r. Therefore the two pairs have exactly the same positive common divisors.

Worked example

Euclidean algorithm for gcd(7224,1290)\gcd(7224,1290)

Apply the division algorithm repeatedly:

7224=12905+774,1290=7741+516,774=5161+258,516=2582+0.\begin{aligned} 7224&=1290\cdot5+774,\\ 1290&=774\cdot1+516,\\ 774&=516\cdot1+258,\\ 516&=258\cdot2+0. \end{aligned}

The last nonzero remainder is 258, so

gcd(7224,1290)=258.\gcd(7224,1290)=258.

The algorithm must terminate because the remainders form a strictly decreasing sequence of nonnegative integers:

r1>r2>r3>0.r_1>r_2>r_3>\cdots\ge0.

A strictly decreasing sequence of nonnegative integers cannot continue forever.

Extended Euclidean algorithm and Bezout's identity

The same computation can be run backward to express the gcd as an integer linear combination of the original two numbers.

Worked example

Back-substitution

From the previous computation,

258=774516.258=774-516.

Substitute 516=1290774516=1290-774:

258=774(1290774)=27741290.258=774-(1290-774)=2\cdot774-1290.

Substitute 774=722451290774=7224-5\cdot1290:

258=2(722451290)1290=27224111290.258=2(7224-5\cdot1290)-1290 =2\cdot7224-11\cdot1290.

Thus

258=72242+1290(11).258=7224\cdot2+1290\cdot(-11).

Theorem

Bezout's identity

For any integers a,b, there exist integers x,y such that

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

This result says that the gcd is not merely the largest common divisor; it is also the smallest positive integer that can be built as an integer linear combination of a and b.

Theorem

Relative primality criterion

Let a,b be nonzero integers. Then a and b are relatively prime if and only if there exist integers x,y such that

ax+by=1.ax+by=1.

One direction is Bezout's identity when gcd(a,b)=1\gcd(a,b)=1. For the converse, if ax+by=1ax+by=1, then every common divisor of a and b must divide 1; hence the greatest positive common divisor is 1.

Worked example

Extended Euclidean table

For 12345 and 11111, the Euclidean algorithm gives

12345=111111+1234,11111=12349+5,1234=5246+4,5=41+1,4=14+0.\begin{aligned} 12345&=11111\cdot1+1234,\\ 11111&=1234\cdot9+5,\\ 1234&=5\cdot246+4,\\ 5&=4\cdot1+1,\\ 4&=1\cdot4+0. \end{aligned}

So the gcd is 1. Back-substitution, or the coefficient table form of the extended Euclidean algorithm, gives

1=12345(2224)+11111(2471).1=12345(-2224)+11111(2471).

This proves in particular that 12345 and 11111 are relatively prime.

Common divisors and Euclid's lemma

Bezout's identity also gives a cleaner characterization of the gcd.

Theorem

Common divisors divide the gcd

For integers a,b,n,

na and nbngcd(a,b).n\mid a\text{ and }n\mid b \quad\Longleftrightarrow\quad n\mid \gcd(a,b).

The forward direction is the useful one. If n divides both a and b, then it divides every linear combination ax+byax+by; in particular, it divides the Bezout combination equal to gcd(a,b)\gcd(a,b).

Theorem

Euclid's lemma

Let p be prime. If pabp\mid ab, then pap\mid a or pbp\mid b.

If pap\nmid a, then gcd(a,p)=1\gcd(a,p)=1, so there exist integers m,n with

am+pn=1.am+pn=1.

Multiplying by b gives

abm+pbn=b.abm+pbn=b.

Since pabp\mid ab, both terms on the left are divisible by p, so pbp\mid b.

Unique prime factorization

Theorem

Fundamental theorem of arithmetic

Every positive integer greater than 1 can be written as a product of primes, and this product is unique up to the order of the factors.

Existence follows from the same least-counterexample strategy used earlier. If there were a least integer greater than 1 that could not be written as a product of primes, it would not be prime, so it would split into smaller factors, and those smaller factors would already have prime factorizations.

Uniqueness uses Euclid's lemma. If

p1p2pr=q1q2qs,p_1p_2\cdots p_r=q_1q_2\cdots q_s,

then p1p_1 divides the right-hand product, so p1p_1 must divide one of the prime factors qjq_j. Hence p1=qjp_1=q_j. Cancel and repeat.

The theorem lets us compute gcds by comparing exponents. If

a=p1m1prmr,b=p1n1prnr,a=p_1^{m_1}\cdots p_r^{m_r}, \qquad b=p_1^{n_1}\cdots p_r^{n_r},

where missing primes have exponent 0, then

gcd(a,b)=p1min(m1,n1)prmin(mr,nr).\gcd(a,b)=p_1^{\min(m_1,n_1)}\cdots p_r^{\min(m_r,n_r)}.

Worked example

Gcd from prime powers

Since

144=2432,60=2235,144=2^4\cdot3^2,\qquad 60=2^2\cdot3\cdot5,

we have

gcd(144,60)=223150=12.\gcd(144,60)=2^2\cdot3^1\cdot5^0=12.

Linear Diophantine equations

An equation

ax+by=cax+by=c

where the unknowns x,y must be integers is called a linear Diophantine equation. Bezout's identity tells us exactly when it is solvable.

Theorem

Solvability criterion

Let a,b,cZa,b,c\in\mathbb Z and let d=gcd(a,b)d=\gcd(a,b). The equation

ax+by=cax+by=c

has an integer solution (x,y) if and only if dcd\mid c.

If a solution exists, then d divides a and b, so d divides ax+by=cax+by=c. Conversely, if c=drc=dr, Bezout's identity gives d=am+bnd=am+bn, and then

c=dr=a(mr)+b(nr).c=dr=a(mr)+b(nr).

Thus (mr,nr) is a solution.

Once one solution is known, all solutions can be described. Suppose d=gcd(a,b)0d=\gcd(a,b)\ne0, put

u=ad,v=bd,u=\frac ad,\qquad v=\frac bd,

and let (x0,y0)(x_0,y_0) be one solution. Then every solution is

x=x0+kv,y=y0ku,kZ.x=x_0+kv,\qquad y=y_0-ku,\qquad k\in\mathbb Z.

Worked example

A measuring problem

Can a 180 mL cup and a 105 mL glass measure exactly 30 mL? Algebraically, we ask whether

180x+105y=30180x+105y=30

has integer solutions. Since

gcd(180,105)=15\gcd(180,105)=15

and 153015\mid 30, the equation is solvable.

Using the extended Euclidean algorithm,

15=18031055.15=180\cdot3-105\cdot5.

Multiplying by 2 gives

30=180610510.30=180\cdot6-105\cdot10.

So one solution is (x,y)=(6,10)(x,y)=(6,-10). Since a/d=12a/d=12 and b/d=7b/d=7, all solutions are

(x,y)=(6+7k,1012k),kZ.(x,y)=(6+7k,-10-12k),\qquad k\in\mathbb Z.

Quick checks

Quick check

What does aba\mid b mean in integer language?

Use the quantifier hidden in the definition.

Solution

Answer

Quick check

Why does every common divisor of a and b divide every expression ax+byax+by with x,yZx,y\in\mathbb Z?

Use the definition of divisibility twice.

Solution

Answer

Quick check

In the Euclidean algorithm for 7224 and 1290, why is the gcd the last nonzero remainder?

Use the identity gcd(a,b)=gcd(b,r)\gcd(a,b)=\gcd(b,r) after each division step.

Solution

Answer

Quick check

What condition decides whether ax+by=cax+by=c has integer solutions?

State it using gcd(a,b)\gcd(a,b).

Solution

Answer

Exercises

  1. List all positive divisors of 84, and compute gcd(84,60)\gcd(84,60).
  2. Use the division algorithm to write 37=5q+r-37=5q+r with 0r<50\le r<5.
  3. Use the Euclidean algorithm to compute gcd(252,198)\gcd(252,198).
  4. Express gcd(252,198)\gcd(252,198) as 252x+198y252x+198y.
  5. Prove that if nan\mid a and nbn\mid b, then ngcd(a,b)n\mid\gcd(a,b).
  6. Determine whether 35x+21y=1435x+21y=14 has integer solutions. If it does, find one.
  7. Determine whether 35x+21y=1035x+21y=10 has integer solutions.
  8. Use prime factorizations to compute gcd(24325,23357)\gcd(2^4\cdot3^2\cdot5,\, 2^3\cdot3^5\cdot7).

Solution

Guided solutions

Section mastery checkpoint

Answer each question correctly to complete this section checkpoint. Correct progress: 0%.

Skills: integer-methods, gcd, euclidean-algorithm

Use the Euclidean algorithm shown in chapter 7: 7224=12905+7747224=1290\cdot5+774, 1290=7741+5161290=774\cdot1+516, 774=5161+258774=516\cdot1+258, 516=2582+0516=258\cdot2+0. Fill in the blank: \gcd(7224,1290)=____.

Attempts used: 0

Attempts remaining: Unlimited attempts

Preview does not consume an attempt.

Submit records a graded attempt.

Syntax guidance: Enter the last nonzero remainder.

  • Enter a single positive integer.

Skills: integer-methods, linear-diophantine-equations, gcd

Which statement correctly decides whether 35x+21y=1035x+21y=10 has integer solutions?

Attempts used: 0

Attempts remaining: Unlimited attempts

Preview does not consume an attempt.

Submit records a graded attempt.

  • 35=7535=7\cdot5 and 21=7321=7\cdot3, so the gcd is 7.

Key terms in this unit

Premium learning add-ons

Core notes stay free. Advanced exercises, video explanations, and premium exports are available through paid plans.