In document A Computational Introduction to Number Theory and Algebra (Page 33-68)

This chapter introduces the basic properties of congruences modulon, along with the related notion of residue classes modulon. Other items discussed include the Chinese remainder theorem, Euler’s phi function, Euler’s theorem, Fermat’s little theorem, quadratic residues, and finally, summations over divisors.

2.1 Equivalence relations

Before discussing congruences, we review the definition and basic properties of equivalence relations.

LetSbe a set. A binary relation∼onSis called anequivalence relationif it is reflexive: aafor allaS,

symmetric: abimpliesbafor alla,bS, and transitive: abandbcimpliesacfor alla,b,cS.

If∼is an equivalence relation onS, then foraSone defines itsequivalence classas the set{x∈S:xa}.

Theorem 2.1. Let ∼be an equivalence relation on a set S, and foraS, let [a]

denote its equivalence class. Then for all a,bS, we have: (i) a∈[a];

(ii) a∈[b]implies[a]=[b].

Proof. (i) follows immediately from reflexivity. For (ii), supposea∈ [b], so that

abby definition. We want to show that [a] = [b]. To this end, consider any

xS. We have

x∈[a] =⇒ xa (by definition)

=⇒ xb (by transitivity, and sincexaandab) =⇒ x∈[b].

Thus, [a]⊆[b]. By symmetry, we also haveba, and reversing the roles ofaand

bin the above argument, we see that [b]⊆[a]. 2

This theorem implies that each equivalence class is non-empty, and that each element of S belongs to a unique equivalence class; in other words, the distinct equivalence classes form a partition of S (see Preliminaries). A member of an equivalence class is called arepresentativeof the class.

EXERCISE 2.1. Consider the relations=,≤, and<on the setR. Which of these are equivalence relations? Explain your answers.

EXERCISE 2.2. LetS := (R×R)\ {(0, 0)}. For (x,y), (x0,y0) ∈ S, let us say (x,y) ∼ (x0,y0) if there exists a real numberλ > 0 such that (x,y) = (λx0,λy0). Show that∼is an equivalence relation; moreover, show that each equivalence class contains a unique representative that lies on the unit circle (i.e., the set of points (x,y) such thatx2+y2 =1).

2.2 Definitions and basic properties of congruences

Letnbe a positive integer. For integersaandb, we say thatais congruent tob

modulonifn|(ab), and we writeab(modn). Ifn-(ab), then we write

a 6≡ b (modn). Equivalently,ab (modn) if and only ifa = b+nyfor some

yZ. The relationab (modn) is called acongruence relation, or simply, a congruence. The numbernappearing in such congruences is called themodulus of the congruence. This usage of the “mod” notation as part of a congruence is not to be confused with the “mod” operation introduced in §1.1.

If we view the modulus n as fixed, then the following theorem says that the binary relation “· ≡ ·(modn)” is an equivalence relation on the setZ.

Theorem 2.2. Let nbe a positive integer. For all a,b,c∈Z, we have:

(i) aa(modn);

(ii) ab(modn)impliesba (modn);

(iii) ab(modn)andbc(modn)implies ac(modn).

2.2 Definitions and basic properties of congruences 17

ab, then it also divides−(ab) =ba. For (iii), observe that ifndividesab

andbc, then it also divides (ab)+(bc)=ac. 2

Another key property of congruences is that they are “compatible” with integer addition and multiplication, in the following sense:

Theorem 2.3. Let a,a0,b,b0,n∈Zwith n >0. If

aa0 (modn) and bb0 (modn),


a+ba0+b0 (modn) and a·bab0 (modn).

Proof. Suppose thataa0 (modn) andbb0 (modn). This means that there exist integersxandysuch thata=a0+nxandb=b0+ny. Therefore,

a+b=a0+b0+n(x+y), which proves the first congruence of the theorem, and

ab=(a0+nx)(b0+ny) =a0b0+n(a0y+b0x+nxy), which proves the second congruence. 2

Theorems 2.2 and 2.3 allow one to work with congruence relations modulo n

much as one would with ordinary equalities: one can add to, subtract from, or multiply both sides of a congruence modulo n by the same integer; also, if bis congruent to a modulo n, one may substitute b for a in any simple arithmetic expression (involving addition, subtraction, and multiplication) appearing in a con- gruence modulon.

Now suppose ais an arbitrary, fixed integer, and consider the set of integersz

that satisfy the congruence za (modn). Since zsatisfies this congruence if and only if z = a +ny for someyZ, we may apply Theorems 1.4 and 1.5 (withaas given, andb:=n) to deduce that every interval ofnconsecutive integers contains exactly one suchz. This simple fact is of such fundamental importance that it deserves to be stated as a theorem:

Theorem 2.4. Let a,n∈Zwith n >0. Then there exists a unique integer zsuch

that za (modn) and 0 ≤ z < n, namely,z := amodn. More generally, for everyx∈R, there exists a unique integer z∈[x,x+n)such thatza(modn). Example 2.1. Let us find the set of solutionszto the congruence

Suppose that zis a solution to (2.1). Subtracting 4 from both sides of (2.1), we obtain

3z≡2 (mod 7). (2.2)

Next, we would like to divide both sides of this congruence by 3, to getzby itself on the left-hand side. We cannot do this directly, but since 5·3≡ 1 (mod 7), we can achieve the same effect by multiplying both sides of (2.2) by 5. If we do this, and then replace 5·3 by 1, and 5·2 by 3, we obtain

z≡3 (mod 7).

Thus, ifzis a solution to (2.1), we must havez≡3 (mod 7); conversely, one can verify that ifz≡3 (mod 7), then (2.1) holds. We conclude that the integerszthat are solutions to (2.1) are precisely those integers that are congruent to 3 modulo 7, which we can list as follows:

. . . ,−18,−11,−4, 3, 10, 17, 24, . . . 2

In the next section, we shall give a systematic treatment of the problem of solving linear congruences, such as the one appearing in the previous example.

EXERCISE 2.3. Leta,b,n∈Zwithn >0. Show thatab(modn) if and only if (amodn)=(bmodn).

EXERCISE 2.4. Let a,b,n ∈ Z with n > 0 and ab (mod n). Also, let

c0,c1, . . . ,ck ∈Z. Show that

c0+c1a+· · ·+ckakc0+c1b+· · ·+ckbk (modn).

EXERCISE 2.5. Leta,b,n,n0 ∈ Zwith n > 0, n0 > 0, andn0 | n. Show that if

ab(modn), thenab(modn0).

EXERCISE 2.6. Leta,b,n,n0 ∈Zwithn > 0, n0 > 0, and gcd(n,n0) = 1. Show that ifab(modn) andab(modn0), thenab(modnn0).

EXERCISE 2.7. Let a,b,nZ with n > 0 and ab (mod n). Show that gcd(a,n)=gcd(b,n).

EXERCISE 2.8. Leta be a positive integer whose base-10 representation isa =

(ak−1· · ·a1a0)10. Letb be the sum of the decimal digits of a; that is, letb := a0+a1+· · ·+ak−1. Show thatab(mod 9). From this, justify the usual “rules of

thumb” for determining divisibility by 9 and 3:ais divisible by 9 (respectively, 3) if and only if the sum of the decimal digits ofais divisible by 9 (respectively, 3).

2.3 Solving linear congruences 19 EXERCISE 2.9. Letebe a positive integer. Fora ∈ {0, . . . , 2e −1}, let ˜adenote the integer obtained by inverting the bits in the e-bit, binary representation of a

(note that ˜a∈ {0, . . . , 2e−1}). Show that ˜a+1≡ −a(mod 2e). This justifies the usual rule for computing negatives in 2’s complement arithmetic (which is really just arithmetic modulo 2e).

EXERCISE 2.10. Show that the equation 7y3+2=z3has no solutionsy,zZ. EXERCISE 2.11. Show that there are 14 distinct, possible, yearly (Gregorian)

calendars, and show that all 14 calendars actually occur. 2.3 Solving linear congruences

In this section, we consider the general problem of solving linear congruences. More precisely, for a given positive integer n, and arbitrary integersa andb, we wish to determine the set of integerszthat satisfy the congruence

azb(modn). (2.3)

Observe that if (2.3) has a solution z, and if zz0 (mod n), then z0 is also a solution to (2.3). However, (2.3) may or may not have a solution, and if it does, such solutions may or may not be uniquely determined modulon. The following theorem precisely characterizes the set of solutions of (2.3); basically, it says that (2.3) has a solution if and only if d := gcd(a,n) divides b, in which case the solution is uniquely determined modulon/d.

Theorem 2.5. Let a,nZwith n >0, and let d:=gcd(a,n).

(i) For every b ∈Z, the congruence azb (modn) has a solution z ∈Zif

and only if d|b.

(ii) For every z∈Z, we haveaz≡0 (modn)if and only if z≡0 (modn/d).

(iii) For allz,z0∈Z, we haveazaz0(modn)if and only if zz0(modn/d).

Proof. For (i), letb∈Zbe given. Then we have

azb(modn) for somez∈Z

⇐⇒ az=b+ny for somez,y ∈Z(by definition of congruence)

⇐⇒ azny=b for somez,yZ ⇐⇒ d|b (by Theorem 1.8). For (ii), we have

n|az ⇐⇒ n/d| (a/d)z ⇐⇒ n/d|z.

except that for the implicationn/d | (a/d)z =⇒ n/d | z, we use Theorem 1.9 and the fact that gcd(a/d,n/d)=1.

For (iii), we have

azaz0 (modn) ⇐⇒ a(zz0)≡0 (modn)

⇐⇒ zz0 ≡0 (modn/d) (by part (ii))

⇐⇒ zz0 (modn/d). 2

We can restate Theorem 2.5 in more concrete terms as follows. Let a,n ∈ Z with n > 0, and let d := gcd(a,n). Let In := {0, . . . ,n−1} and consider the “multiplication bya” map

τa: InIn

z7→azmodn. The image ofτaconsists of then/dintegers

i·d (i=0, . . . ,n/d−1).

Moreover, every elementbin the image ofτahas preciselydpre-images

z0+j·(n/d) (j =0, . . . ,d−1),

wherez0 ∈ {0, . . . ,n/d−1}. In particular,τais a bijection if and only ifaandn

are relatively prime.

Example 2.2. The following table illustrates what Theorem 2.5 says forn = 15 anda=1, 2, 3, 4, 5, 6. z 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 2zmod 15 0 2 4 6 8 10 12 14 1 3 5 7 9 11 13 3zmod 15 0 3 6 9 12 0 3 6 9 12 0 3 6 9 12 4zmod 15 0 4 8 12 1 5 9 13 2 6 10 14 3 7 11 5zmod 15 0 5 10 0 5 10 0 5 10 0 5 10 0 5 10 6zmod 15 0 6 12 3 9 0 6 12 3 9 0 6 12 3 9

In the second row, we are looking at the values 2zmod 15, and we see that this row is just a permutation of the first row. So for every b, there exists a uniquez

such that 2zb(mod 15). This is implied by the fact that gcd(2, 15)=1.

In the third row, the only numbers hit are the multiples of 3, which follows from the fact that gcd(3, 15)=3. Also note that the pattern in this row repeats every five columns; that is, 3z≡3z0 (mod 15) if and only ifzz0(mod 5).

In the fourth row, we again see a permutation of the first row, which follows from the fact that gcd(4, 15)=1.

2.3 Solving linear congruences 21 In the fifth row, the only numbers hit are the multiples of 5, which follows from the fact that gcd(5, 15) = 5. Also note that the pattern in this row repeats every three columns; that is, 5z≡5z0 (mod 15) if and only ifzz0 (mod 3).

In the sixth row, since gcd(6, 15) = 3, we see a permutation of the third row. The pattern repeats after five columns, although the pattern is a permutation of the pattern in the third row. 2

We develop some further consequences of Theorem 2.5.

A cancellation law. Leta,n∈Zwithn >0. Part (iii) of Theorem 2.5 gives us a cancellation lawfor congruences:

if gcd(a,n) =1 andazaz0(modn), thenzz0 (modn).

More generally, ifd:=gcd(a,n), then we can cancelafrom both sides of a con- gruence modulon, as long as we replace the modulus byn/d.

Example 2.3. Observe that

5·2≡5·(−4) (mod 6). (2.4)

Part (iii) of Theorem 2.5 tells us that since gcd(5, 6) = 1, we may cancel the common factor of 5 from both sides of (2.4), obtaining 2 ≡ −4 (mod 6), which one can also verify directly.

Next observe that

15·5≡15·3 (mod 6). (2.5)

We cannot simply cancel the common factor of 15 from both sides of (2.5); indeed, 56≡3 (mod 6). However, gcd(15, 6)=3, and as part (iii) of Theorem 2.5 guaran- tees, we do indeed have 5≡3 (mod 2). 2

Modular inverses. Again, let a,n ∈ Z with n > 0. We say that z ∈ Z is a multiplicative inverse ofamodulonifaz≡ 1 (modn). Part (i) of Theorem 2.5 says that a has a multiplicative inverse modulo n if and only if gcd(a,n) = 1. Moreover, part (iii) of Theorem 2.5 says that the multiplicative inverse of a, if it exists, is uniquely determined modulon; that is, if z andz0 are multiplicative inverses of a modulon, then zz0 (modn). Note that if zis a multiplicative inverse ofamodulon, thenais a multiplicative inverse ofzmodulon. Also note that ifaa0 (modn), thenzis a multiplicative inverse ofamodulonif and only ifzis a multiplicative inverse ofa0modulon.

Now suppose thata,b,nZwithn >0,a6=0, and gcd(a,n)=1. Theorem 2.5 says that there exists a unique integerzsatisfying

Setting s := b/aQ, we may generalize the “mod” operation, definingsmod

n to be this value z. As the reader may easily verify, this definition of smodn

does not depend on the particular choice of fraction used to represent the rational numbers. With this notation, we can simply writea−1modnto denote the unique multiplicative inverse ofamodulonthat lies in the interval 0, . . . ,n−1.

Example 2.4. Looking back at the table in Example 2.2, we see that 2−1mod 15=8 and 4−1 mod 15=4, and that neither 3, 5, nor 6 have modular inverses modulo 15. 2

Example 2.5. Leta,b,n∈Zwithn >0. We can describe the set of solutionsz∈Z to the congruenceazb(modn) very succinctly in terms of modular inverses.

If gcd(a,n) = 1, then settingt := a−1 modn, andz0 := tbmodn, we see that z0is the unique solution to the congruenceazb(modn) that lies in the interval {0, . . . ,n−1}.

More generally, if d := gcd(a,n), then the congruence azb (mod n) has a solution if and only if d | b. So suppose that d | b. In this case, if we set

a0 :=a/d,b0 :=b/d, andn0 :=n/d, then for eachzZ, we haveazb(modn) if and only if a0zb0 (mod n0). Moreover, gcd(a0,n0) = 1, and therefore, if we set t := (a0)−1modn0 and z0 := tb0modn0, then the solutions to the con-

gruenceazb (mod n) that lie in the interval {0, . . . ,n−1}are thedintegers

z0,z0+n0, . . . ,z0+(d−1)n0. 2

EXERCISE 2.12. Leta1, . . . ,ak,b,nbe integers with n > 0. Show that the con-


a1z1+· · ·+akzkb(modn)

has a solutionz1, . . . ,zk ∈Zif and only ifd|b, whered:=gcd(a1, . . . ,ak,n).

EXERCISE 2.13. Letpbe a prime, and leta,b,c,ebe integers, such thate > 0,

a 6≡ 0 (mod pe+1), and 0 ≤ c < pe. Define N to be the number of integers

z∈ {0, . . . ,p2e−1}such that j

(az+b) modp2epek=c. Show thatN=pe.

2.4 The Chinese remainder theorem

Next, we consider systems of linear congruences with respect to moduli that are relatively prime in pairs. The result we state here is known as the Chinese remain- der theorem, and is extremely useful in a number of contexts.

2.4 The Chinese remainder theorem 23 Theorem 2.6 (Chinese remainder theorem). Let{ni}ki=1be a pairwise relatively

prime family of positive integers, and let a1, . . . ,ak be arbitrary integers. Then

there exists a solutionaZto the system of congruences

aai(modni) (i=1, . . . ,k).

Moreover, any a0 ∈ Zis a solution to this system of congruences if and only if

aa0(modn), wheren:=Qk i=1ni.

Proof. To prove the existence of a solutionato the system of congruences, we first show how to construct integerse1, . . . ,ek such that fori,j=1, . . . ,k, we have


1 (modni) ifj =i,

0 (modni) ifj 6=i. (2.6)

If we do this, then setting




i=1 aiei, one sees that forj=1, . . . ,k, we have





since all the terms in this sum are zero modulonj, except for the termi=j, which is congruent toajmodulonj.

To constructe1, . . . ,ek satisfying (2.6), letn := Q k

i=1nias in the statement of

the theorem, and fori = 1, . . . ,k, letni := n/ni; that is,ni is the product of all

the modulinj withj 6= i. From the fact that{ni}ki=1is pairwise relatively prime,

it follows that for i = 1, . . . ,k, we have gcd(ni,ni) = 1, and so we may define ti := (ni)−1modniandei:=niti. One sees thatei ≡1 (modni), while forj 6=i, we haveni|nj, and soej≡0 (modni). Thus, (2.6) is satisfied.

That proves the existence of a solutionato the given system of congruences. If

aa0 (modn), then sinceni|nfori=1, . . . ,k, we see thata0 ≡aai(modni) fori=1, . . . ,k, and soa0also solves the system of congruences.

Finally, if a0 is a solution to the given system of congruences, thenaaia0 (modni) fori= 1, . . . ,k. Thus,ni | (aa0) fori =1, . . . ,k. Since{ni}ki=1is pairwise relatively prime, this impliesn|(a−a0), or equivalently,aa0(modn).2 We can restate Theorem 2.6 in more concrete terms, as follows. For each positive integerm, letIm denote{0, . . . ,m−1}. Suppose{ni}ki=1 is a pairwise relatively

prime family of positive integers, and setn:=n1· · ·nk. Then the map τ : InIn1× · · · ×Ink

a7→(amodn1, . . . ,amodnk)

is a bijection.

Example 2.6. The following table illustrates what Theorem 2.6 says forn1 = 3


a 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14

amod 3 0 1 2 0 1 2 0 1 2 0 1 2 0 1 2

amod 5 0 1 2 3 4 0 1 2 3 4 0 1 2 3 4

We see that asa ranges from 0 to 14, the pairs (amod 3,amod 5) range over all pairs (a1,a2) witha1 ∈ {0, 1, 2}anda2 ∈ {0, . . . , 4}, with every pair being hit

exactly once. 2

EXERCISE 2.14. Compute the valuese1,e2,e3in the proof of Theorem 2.6 in the

case wherek = 3, n1 = 3,n2 = 5, andn3 = 7. Also, find an integerasuch that a≡1 (mod 3),a≡ −1 (mod 5), anda≡5 (mod 7).

EXERCISE 2.15. If you want to show that you are a real nerd, here is an age-

guessing game you might play at a party. You ask a fellow party-goer to divide his age by each of the numbers 3, 4, and 5, and tell you the remainders. Show how to use this information to determine his age.

EXERCISE 2.16. Let {ni}ki=1 be a pairwise relatively prime family of positive

integers. Let a1, . . . ,ak and b1, . . . ,bk be integers, and set di := gcd(ai,ni) for i = 1, . . . ,k. Show that there exists an integerzsuch thataizbi (modni) for i=1, . . . ,kif and only ifdi|bifori=1, . . . ,k.

EXERCISE 2.17. For each primep, letνp(·) be defined as in §1.3. Letp1, . . . ,pr

be distinct primes,a1, . . . ,arbe arbitrary integers, ande1, . . . ,erbe arbitrary non-

negative integers. Show that there exists an integerasuch thatνpi(aai) =eifor

i=1, . . . ,r.

EXERCISE2.18. Supposen1andn2are positive integers, and letd:=gcd(n1,n2).

Leta1 anda2 be arbitrary integers. Show that there exists an integerasuch that aa1(modn1) andaa2 (modn2) if and only ifa1 ≡a2(modd).

2.5 Residue classes 25 2.5 Residue classes

As we already observed in Theorem 2.2, for any fixed positive integern, the binary relation “· ≡ · (mod n)” is an equivalence relation on the set Z. As such, this relation partitions the setZ into equivalence classes. We denote the equivalence class containing the integeraby [a]n, and whennis clear from context, we simply

write [a]. By definition, we have

z∈[a] ⇐⇒ za(modn) ⇐⇒ z=a+nyfor somey ∈Z, and hence


Historically, these equivalence classes are calledresidue classes modulon, and we shall adopt this terminology here as well. Note that a given residue class modulon

In document A Computational Introduction to Number Theory and Algebra (Page 33-68)