Mathematics · Book 2 · Grades 10–12

High School Mathematics

High School Mathematics · Grades 10–12

29Arithmetic

Arithmetic studies the integers: divisibility, prime numbers, remainders. Long considered the purest of pure mathematics, it now protects every online payment: the RSA cryptosystem rests on the theorems of Bézout, Gauss and Fermat proved in this chapter.

29.1 Divisibility and Euclidean division

Definition 29.1 (Divisibility)

Let a,bZa, b \in \Z. We say bb divides aa, written bab \mid a, if there exists kZk \in \Z with a=kba = kb. We also say aa is a multiple of bb.

Proposition 29.2

If cac \mid a and cbc \mid b, then cc divides every integer combination au+bvau + bv (u,vZu, v \in \Z). If aba \mid b and bab \mid a with a,bNa,b \in \N, then a=ba = b. If aba \mid b and b0b \neq 0, then ab\abs a \leq \abs b.

Proof. Write a=kca = kc, b=lcb = lc: then au+bv=(ku+lv)cau + bv = (ku + lv)c. The other points follow from a=kb\abs{a} = \abs{k}\,\abs{b} with k1\abs k \geq 1 when b=ka0b = ka \neq 0.

Theorem 29.3 (Euclidean division)

Let aZa \in \Z and bNb \in \N^*. There exists a unique pair (q,r)Z×N(q, r) \in \Z \times \N such that

a=bq+rand0r<b.a = bq + r \qquad\text{and}\qquad 0 \leq r < b .

qq is the quotient and rr the remainder.

Proof. Existence. The set of multiples of bb not exceeding aa has a largest element bqbq (it is nonempty and bounded above); set r=abqr = a - bq. By maximality, b(q+1)>ab(q+1) > a, so 0r<b0 \leq r < b. Uniqueness. If bq+r=bq+rbq + r = bq' + r' with 0r,r<b0 \leq r, r' < b, then b(qq)=rrb(q - q') = r' - r and rr<b\abs{r' - r} < b: a multiple of bb of absolute value less than bb must be 00, so r=rr = r' and q=qq = q'.

29.2 Congruences

Definition 29.4 (Congruence)

Let nNn \in \N^*. Two integers a,ba, b are congruent modulo nn, written ab(modn)a \equiv b \pmod n, if n(ab)n \mid (a - b) — equivalently, if aa and bb have the same remainder in the Euclidean division by nn.

Proposition 29.5 (Compatibility with operations)

If ab(modn)a \equiv b \pmod n and cd(modn)c \equiv d \pmod n, then

a+cb+d,acbd,akbk (kN)(modn).a + c \equiv b + d, \qquad ac \equiv bd, \qquad a^k \equiv b^k \ (k \in \N) \pmod n .

Proof. nn divides (ab)+(cd)=(a+c)(b+d)(a-b) + (c-d) = (a+c) - (b+d), and acbd=a(cd)+d(ab)ac - bd = a(c - d) + d(a - b) is also a multiple of nn. The power rule follows by induction from the product rule.

Method 29.6 (Computing powers modulo nn)

To compute akmodna^k \bmod n, reduce the base modulo nn, then look for a small power of aa congruent to ±1\pm1, and use it to collapse the exponent. For instance 2100mod72^{100} \bmod 7: since 23=81(mod7)2^3 = 8 \equiv 1 \pmod 7 and 100=3×33+1100 = 3\times33 + 1,

2100=(23)33×2133×2=2(mod7).2^{100} = \left(2^{3}\right)^{33} \times 2 \equiv 1^{33}\times 2 = 2 \pmod 7 .

29.3 GCD, Bézout and Gauss

Definition 29.7 (GCD)

Let a,ba, b be integers, not both zero. The greatest common divisor gcd(a,b)\gcd(a, b) is the largest integer dividing both aa and bb. When gcd(a,b)=1\gcd(a,b) = 1, aa and bb are said to be coprime.

Proposition 29.8 (Euclid’s algorithm)

If a=bq+ra = bq + r (b0b \neq 0), then gcd(a,b)=gcd(b,r)\gcd(a, b) = \gcd(b, r). Iterating the Euclidean division therefore computes gcd(a,b)\gcd(a,b): the gcd is the last nonzero remainder.

Proof. Any common divisor of aa and bb divides r=abqr = a - bq (Proposition 29.2), hence is a common divisor of bb and rr; and conversely, since a=bq+ra = bq + r. The two pairs have the same common divisors, so the same gcd. The algorithm terminates because the remainders form a strictly decreasing sequence of nonnegative integers.

Example 29.9

gcd(252,198)\gcd(252, 198): 252=198+54252 = 198 + 54; 198=3×54+36198 = 3\times54 + 36; 54=36+1854 = 36 + 18; 36=2×18+036 = 2 \times 18 + 0. Hence gcd(252,198)=18\gcd(252,198) = 18.

Theorem 29.10 (Bézout’s identity)

Let a,ba, b be integers, not both zero, and d=gcd(a,b)d = \gcd(a,b). There exist u,vZu, v \in \Z such that

au+bv=d.au + bv = d .

In particular, aa and bb are coprime if and only if au+bv=1au + bv = 1 for some integers u,vu, v.

Proof. Run Euclid’s algorithm backwards: each remainder is an integer combination of the previous two, and the initial data a,ba, b are combinations of themselves; by descending substitution, the last nonzero remainder dd is an integer combination of aa and bb. (In Example 29.9: 18=5436=54(1983×54)=4×54198=4(252198)198=4×2525×19818 = 54 - 36 = 54 - (198 - 3\times54) = 4\times54 - 198 = 4(252 - 198) - 198 = 4\times252 - 5\times198.)

For the equivalence: if gcd(a,b)=1\gcd(a,b) = 1, Bézout provides u,vu, v; conversely, any common divisor of aa and bb divides au+bv=1au + bv = 1, forcing gcd(a,b)=1\gcd(a,b) = 1.

Theorem 29.11 (Gauss’s lemma)

Let a,b,cZa, b, c \in \Z. If abca \mid bc and gcd(a,b)=1\gcd(a, b) = 1, then aca \mid c.

Proof. Bézout gives au+bv=1au + bv = 1; multiply by cc: acu+bcv=cacu + bcv = c. Both terms of the left side are multiples of aa (the second because abca \mid bc), hence so is cc.

Corollary 29.12

If aca \mid c, bcb \mid c and gcd(a,b)=1\gcd(a,b) = 1, then abcab \mid c.

Proof. Write c=akc = ak. From bakb \mid ak and gcd(a,b)=1\gcd(a,b)=1, Gauss gives bkb \mid k, say k=blk = bl; then c=ablc = abl.

29.4 Prime numbers

Definition 29.13 (Prime)

An integer p2p \geq 2 is prime if its only positive divisors are 11 and pp.

Proposition 29.14

Every integer n2n \geq 2 has a prime divisor; if nn is not prime, it has a prime divisor n\leq \sqrt n. If a prime pp divides a product abab, then pap \mid a or pbp \mid b (Euclid’s lemma).

Proof. The smallest divisor d2d \geq 2 of nn is prime (any proper divisor of dd would be a smaller divisor of nn). If n=den = de is composite with 2de2 \leq d \leq e, then d2de=nd^2 \leq de = n, so dnd \leq \sqrt n. For Euclid’s lemma: if pap \nmid a, then gcd(p,a)=1\gcd(p, a) = 1 (the only divisors of pp are 11 and pp), and Gauss’s lemma gives pbp \mid b.

Theorem 29.15 (Euclid)

There are infinitely many primes.

Proof. Given any finite list p1,,pkp_1, \dots, p_k of primes, consider N=p1p2pk+1N = p_1 p_2 \cdots p_k + 1. Some prime pp divides NN; but no pip_i divides NN (the remainder is 11), so pp is a prime not in the list. No finite list exhausts the primes.

Theorem 29.16 (Fundamental theorem of arithmetic)

Every integer n2n \geq 2 is a product of primes, and this factorization is unique up to the order of the factors:

n=p1α1p2α2prαr,p1<p2<<pr primes, αi1.n = p_1^{\alpha_1} p_2^{\alpha_2} \cdots p_r^{\alpha_r}, \qquad p_1 < p_2 < \dots < p_r \text{ primes},\ \alpha_i \geq 1 .

Proof. Existence, by strong induction: nn prime is its own factorization; otherwise n=den = de with 2d,e<n2 \leq d, e < n, and both factor by the induction hypothesis. Uniqueness: suppose p1ps=q1qtp_1\cdots p_s = q_1 \cdots q_t (primes, with repetitions allowed). By Euclid’s lemma, p1p_1 divides some qjq_j, and being prime, p1=qjp_1 = q_j; cancel and repeat. The two factorizations match term by term.

Theorem 29.17 (Fermat’s little theorem)

Let pp be prime and aZa \in \Z with pap \nmid a. Then

ap11(modp).a^{p-1} \equiv 1 \pmod p .

For every aZa \in \Z (no coprimality assumed), apa(modp)a^p \equiv a \pmod p.

Proof. Consider the p1p - 1 integers a,2a,3a,,(p1)aa, 2a, 3a, \dots, (p-1)a modulo pp. None is 0\equiv 0 (if pkap \mid ka with 1kp11 \leq k \leq p-1, Euclid’s lemma forces pkp \mid k, impossible), and they are pairwise distinct modulo pp (if kalaka \equiv la, then p(kl)ap \mid (k - l)a, so pklp \mid k - l, so k=lk = l). Hence, modulo pp, they are the numbers 1,2,,p11, 2, \dots, p-1 in some order. Multiplying all congruences:

ap1(p1)!(p1)!(modp).a^{p-1}\,(p-1)! \equiv (p-1)! \pmod p .

Since pp divides none of 1,,p11, \dots, p-1, repeated use of Euclid’s lemma allows cancelling (p1)!(p-1)!, leaving ap11a^{p-1} \equiv 1. The second form follows by multiplying by aa (and is trivial when pap \mid a).

Example 29.18 (Application to cryptography)

Fermat’s theorem makes exponentiation modulo nn reversible when the exponents are chosen suitably — the heart of the RSA cryptosystem. With p,qp, q large primes and n=pqn = pq, one publishes nn and an exponent ee; encryption is xxemodnx \mapsto x^e \bmod n. Decrypting requires an exponent dd with ed1(mod(p1)(q1))ed \equiv 1 \pmod{(p-1)(q-1)}, which only someone knowing pp and qq can compute — and recovering p,qp, q from nn means factoring a number hundreds of digits long, which no known algorithm does in reasonable time.

29.5 Exercises

Exercise 29.1

Compute the quotient and remainder of the Euclidean division of 20262026 by 1717, and of 2026-2026 by 1717.

Solution

Solution of Exercise 29.1.

17×119=202317 \times 119 = 2023, so 2026=17×119+32026 = 17 \times 119 + 3: quotient 119119, remainder 33. For 2026-2026: 2026=17×(120)+14-2026 = 17\times(-120) + 14 (indeed 17×120=204017 \times 120 = 2040 and 20402026=142040 - 2026 = 14): quotient 120-120, remainder 1414 (the remainder must lie in [0,17)\intco{0}{17}, so it is not 3-3).

Exercise 29.2

What is the remainder of 71007^{100} modulo 1010? (What is the last digit of 71007^{100}?)

Solution

Solution of Exercise 29.2.

Modulo 1010: 72=49917^2 = 49 \equiv 9 \equiv -1. Hence 7100=(72)50(1)50=1(mod10)7^{100} = \left(7^2\right)^{50} \equiv (-1)^{50} = 1 \pmod{10}: the last digit of 71007^{100} is 11.

Exercise 29.3

Using Euclid’s algorithm, compute gcd(1071,462)\gcd(1071, 462), and find integers u,vu, v with 1071u+462v=gcd(1071,462)1071u + 462v = \gcd(1071, 462).

Solution

Solution of Exercise 29.3.

Euclid: 1071=2×462+1471071 = 2\times462 + 147; 462=3×147+21462 = 3\times147 + 21; 147=7×21+0147 = 7\times21 + 0. So gcd=21\gcd = 21.

Back-substitution: 21=4623×147=4623(10712×462)=7×4623×107121 = 462 - 3\times147 = 462 - 3(1071 - 2\times462) = 7\times462 - 3\times1071. Thus u=3u = -3, v=7v = 7: 1071×(3)+462×7=211071\times(-3) + 462\times7 = 21.

Exercise 29.4

Show that for every nZn \in \Z, n2n^2 is congruent to 00 or 11 modulo 44. Deduce that an integer 3(mod4)\equiv 3 \pmod 4 is never a sum of two squares.

Solution

Solution of Exercise 29.4.

Every integer is 0,1,2\equiv 0, 1, 2 or 3(mod4)3 \pmod 4, and squaring: 0200^2 \equiv 0, 1211^2 \equiv 1, 22=402^2 = 4 \equiv 0, 32=913^2 = 9 \equiv 1. So n20n^2 \equiv 0 or 1(mod4)1 \pmod 4. A sum of two squares is then congruent to 0+00 + 0, 0+10 + 1 or 1+11 + 1, i.e. to 00, 11 or 2(mod4)2 \pmod 4 — never to 33.

Exercise 29.5 ★★

Show that for all nNn \in \N, n(n+1)(2n+1)n(n+1)(2n+1) is divisible by 66.

Solution

Solution of Exercise 29.5.

Divisibility by 22: among nn and n+1n + 1, one is even. Divisibility by 33: if n0n \equiv 0, then 3n3 \mid n; if n1(mod3)n \equiv 1 \pmod 3, then 2n+1302n + 1 \equiv 3 \equiv 0; if n2n \equiv 2, then n+10n + 1 \equiv 0. In all cases 33 divides the product. Since gcd(2,3)=1\gcd(2,3) = 1, Corollary 29.12 gives 6n(n+1)(2n+1)6 \mid n(n+1)(2n+1). (This also re-proves that n(n+1)(2n+1)6\frac{n(n+1)(2n+1)}{6}, the sum of squares of Exercise 20.1, is an integer.)

Exercise 29.6 ★★

Solve in Z\Z the congruence 5x3(mod11)5x \equiv 3 \pmod{11}. (Hint: find the inverse of 55 modulo 1111.)

Solution

Solution of Exercise 29.6.

We look for the inverse of 55 modulo 1111: testing (or Bézout), 5×9=45=44+11(mod11)5 \times 9 = 45 = 44 + 1 \equiv 1 \pmod{11}. Multiplying the congruence by 99:

x9×3=275(mod11).x \equiv 9 \times 3 = 27 \equiv 5 \pmod{11}.

The solutions are the integers x=5+11kx = 5 + 11k, kZk \in \Z. (Check: 5×5=253(mod11)5\times5 = 25 \equiv 3 \pmod{11}.)

Exercise 29.7 ★★

Solve in Z×Z\Z \times \Z the Diophantine equation

17x40y=1,17x - 40y = 1,

then describe all solutions of 17x40y=617x - 40y = 6.

Solution

Solution of Exercise 29.7.

gcd(17,40)=1\gcd(17, 40) = 1, so solutions exist. Euclid: 40=2×17+640 = 2\times17 + 6; 17=2×6+517 = 2\times6 + 5; 6=5+16 = 5 + 1. Back-substituting: 1=65=6(172×6)=3×617=3(402×17)17=3×407×171 = 6 - 5 = 6 - (17 - 2\times6) = 3\times6 - 17 = 3(40 - 2\times17) - 17 = 3\times40 - 7\times17. Hence 17×(7)40×(3)=117\times(-7) - 40\times(-3) = 1: the particular solution (x0,y0)=(7,3)(x_0, y_0) = (-7, -3).

General solution of 17x40y=117x - 40y = 1: subtracting the particular relation, 17(x+7)=40(y+3)17(x + 7) = 40(y + 3); since gcd(17,40)=1\gcd(17, 40) = 1, Gauss gives 40x+740 \mid x + 7, so x=7+40kx = -7 + 40k and then y=3+17ky = -3 + 17k, kZk \in \Z (all of which check).

For 17x40y=617x - 40y = 6, multiply the particular solution by 66: (x1,y1)=(42,18)(x_1, y_1) = (-42, -18), and the same reasoning gives

x=42+40k,y=18+17k,kZ.x = -42 + 40k, \qquad y = -18 + 17k, \qquad k \in \Z .

(E.g. k=2k = 2: x=38x = 38, y=16y = 16; indeed 17×3840×16=646640=617\times38 - 40\times16 = 646 - 640 = 6.)

Exercise 29.8 ★★

Show that 2\sqrt2 is irrational, using the uniqueness of prime factorization (compare the exponent of 22 on both sides of a2=2b2a^2 = 2b^2).

Solution

Solution of Exercise 29.8.

Suppose 2=ab\sqrt2 = \frac ab with a,bNa, b \in \N^*; then a2=2b2a^2 = 2b^2. In the prime factorization of a square, every exponent is even; so the exponent of 22 in a2a^2 is even, while in 2b22b^2 it is odd (one more than an even number). Two factorizations of the same integer with different exponents of 22 contradict the uniqueness in Theorem 29.16. Hence no such fraction exists: 2Q\sqrt2 \notin \Q.

Exercise 29.9 ★★★

Let pp be a prime.

  1. Show that for 1kp11 \leq k \leq p - 1, pp divides (pk)\dbinom{p}{k}. (Hint: use k(pk)=p(p1k1)k\binom pk = p\binom{p-1}{k-1}, Exercise 27.7, and Gauss’s lemma.)
  2. Deduce, by induction on a0a \geq 0, another proof of Fermat’s little theorem in the form apa(modp)a^p \equiv a \pmod p.
Solution

Solution of Exercise 29.9.

1. From k(pk)=p(p1k1)k\binom pk = p \binom{p-1}{k-1}, pp divides k(pk)k\binom pk. For 1kp11 \leq k \leq p-1, pkp \nmid k and pp prime give gcd(p,k)=1\gcd(p, k) = 1, so Gauss’s lemma yields p(pk)p \mid \binom pk.

2. Induction on aa. For a=0a = 0: 0p00^p \equiv 0. Assume apa(modp)a^p \equiv a \pmod p. By the binomial theorem,

(a+1)p=k=0p(pk)akap+1(modp),(a+1)^p = \sum_{k=0}^{p} \binom pk a^k \equiv a^p + 1 \pmod p,

all middle terms vanishing modulo pp by point 1. By the induction hypothesis, (a+1)pa+1(modp)(a+1)^p \equiv a + 1 \pmod p. This proves apaa^p \equiv a for all aNa \in \N, and the case a<0a < 0 follows by writing aa+kpa \equiv a + kp for a suitable positive representative.

Exercise 29.10 ★★★

(Chinese remainder problem.) Find all integers nn such that

n2(mod3),n3(mod5),n2(mod7).n \equiv 2 \pmod 3, \qquad n \equiv 3 \pmod 5, \qquad n \equiv 2 \pmod 7 .

(Hint: solve the first two conditions, then incorporate the third; Bézout coefficients help.)

Solution

Solution of Exercise 29.10.

n2(mod3)n \equiv 2 \pmod 3 and n3(mod5)n \equiv 3 \pmod 5: write n=2+3sn = 2 + 3s; then 2+3s3(mod5)2 + 3s \equiv 3 \pmod 5, i.e. 3s1(mod5)3s \equiv 1 \pmod 5. The inverse of 33 modulo 55 is 22 (3×2=613\times2 = 6 \equiv 1), so s2(mod5)s \equiv 2 \pmod 5, say s=2+5ts = 2 + 5t, and n=8+15tn = 8 + 15t: the first two conditions mean n8(mod15)n \equiv 8 \pmod{15}.

Adding n2(mod7)n \equiv 2 \pmod 7: 8+15t2(mod7)8 + 15t \equiv 2 \pmod 7, and 151(mod7)15 \equiv 1 \pmod 7, so t61(mod7)t \equiv -6 \equiv 1 \pmod 7, say t=1+7ut = 1 + 7u. Hence n=23+105un = 23 + 105u:

n23(mod105).n \equiv 23 \pmod{105}.

(Check: 23=3×7+2=5×4+3=7×3+223 = 3\times7 + 2 = 5\times4 + 3 = 7\times3 + 2.)

29.6 Problem: Secret codes and check digits

Problem 29.1

Weekend problem — congruences guard every barcode and credit card, and Fermat’s little theorem runs the lock on the world’s secrets

G. H. Hardy boasted in 1940 that number theory was “unsullied” by applications. Eighty years later, every barcode beep, every credit-card payment and every encrypted message contradicts him — with exactly this chapter’s tools: congruences (Proposition 29.5), Bézout inverses (Theorem 29.10) and Fermat’s little theorem (Exercise 29.9). This problem checks the codes, breaks a toy version of the lock, and learns why the real lock holds.

Part I — Congruence fluency.

  1. Compute 2026mod72026 \bmod 7; then the last digit of 71007^{100} (find the cycle of powers of 77 modulo 1010).
  2. Fast exponentiation (Method 29.6): compute 5117mod135^{117} \bmod 13 (start from 5215^2 \equiv -1).
  3. Solve 3x5(mod7)3x \equiv 5 \pmod 7.
  4. Run Euclid’s algorithm on (97,35)(97, 35), back-substitute to find integers u,vu, v with 97u+35v=197u + 35v = 1, and deduce the inverse of 3535 modulo 9797.
  5. State precisely when aa is invertible modulo nn, and which theorem delivers the inverse.

Part II — Check digits.

  1. ISBN-10: the ten digits d1d10d_1 \dots d_{10} of a book code must satisfy 10d1+9d2++2d9+1d100(mod11)10d_1 + 9d_2 + \dots + 2d_9 + 1d_{10} \equiv 0 \pmod{11}. Verify the real ISBN 03064061520\,306\,40615\,2.
  2. Prove that the ISBN scheme detects every single-digit error: if one digit changes by d≢0d \not\equiv 0, the weighted sum changes by wdw d with 1w101 \leq w \leq 10 — why can this never be 0(mod11)\equiv 0 \pmod{11} (Theorem 29.11)?
  3. Prove it also detects every transposition of two adjacent (distinct) digits. Then explain the design secret: what property of 1111 made both proofs work, and what could go wrong with modulus 1010?
  4. EAN-13 barcodes weight the digits 1,3,1,3,1, 3, 1, 3, \dots modulo 1010. Compute the check digit completing 978294019905978\,2940199\,05. Which adjacent transpositions does EAN fail to detect? (When is 2(ab)0(mod10)2(a - b) \equiv 0 \pmod{10}?)
  5. Credit cards use Luhn’s scheme: from the right, double every second digit (subtracting 99 when the double exceeds 99), sum everything, and require a multiple of 1010. Verify the test number 45391488034364674539\,1488\,0343\,6467.
  6. In one sentence: what did the prime modulus buy ISBN that EAN and Luhn, chained to 1010, cannot have?

Part III — Fermat’s lock.

  1. A trap before the treasure: compute 210mod3412^{10} \bmod 341, deduce 2340mod3412^{340} \bmod 341 — and then factor 341341. What does this example (a Fermat pseudoprime) say about using Fermat’s little theorem as a primality test?
  2. RSA in miniature: take p=3p = 3, q=11q = 11, so n=33n = 33 and (p1)(q1)=20(p-1)(q-1) = 20; the public exponent is e=3e = 3. Find the private exponent dd with 3d1(mod20)3d \equiv 1 \pmod{20} (question 4’s method).
  3. Encrypt the message m=4m = 4: compute c=m3mod33c = m^3 \bmod 33.
  4. Decrypt: compute cdmod33c^d \bmod 33 (use c2(mod33)c \equiv -2 \pmod{33}) and recover the message.
  5. Why decryption always works: show that m21mm^{21} \equiv m both modulo 33 and modulo 1111 (Fermat’s little theorem in each world), and conclude modulo 3333 (Theorem 29.11 glues the two congruences). Where did 21=ed21 = ed’s special form 1+20k1 + 20k enter?
  6. The lock’s safety: everyone knows nn and ee; recovering dd requires (p1)(q1)(p-1)(q-1), hence the factors of nn. Our 3333 factors at sight — why does the same scheme, with nn of six hundred digits, protect the world’s banks? (One sentence on the asymmetry between multiplying and factoring.)

Part IV — Classics.

  1. The old Chinese soldier count (compare Exercise 29.10): a number of soldiers leaves remainder 22 when ranked by 33 and remainder 33 when ranked by 55. Find all possible counts, and explain why the answer is unique modulo 1515.
  2. One-line proofs at last: from 101(mod9)10 \equiv 1 \pmod 9, prove that every number is congruent to its digit sum modulo 99; from 101(mod11)10 \equiv -1 \pmod{11}, derive the alternating-sum rule for 1111. (The Middle School volume proved these with explicit algebra — admire the compression.)
  3. Finale — Hardy against the barcode: recap the chapter’s toolkit (congruence arithmetic, Bézout inverses, Fermat’s little theorem, gluing coprime moduli) and where each clicked into place in this problem; then give the modern verdict on “unsullied”.
Solution

Solution of Problem 29.1.

1. 2026=289×7+32026 = 289 \times 7 + 3: 20263(mod7)2026 \equiv 3 \pmod 7. Powers of 77 mod 1010: 7,9,3,17, 9, 3, 1, cycle of length 44; 1000(mod4)100 \equiv 0 \pmod 4: last digit of 71007^{100} is 11.

2. 52=251(mod13)5^2 = 25 \equiv -1 \pmod{13}, so 5116=(52)58(1)58=15^{116} = \left(5^2\right)^{58} \equiv (-1)^{58} = 1 and 51175(mod13)5^{117} \equiv 5 \pmod{13}.

3. The inverse of 33 modulo 77 is 55 (15115 \equiv 1): x5×5=254(mod7)x \equiv 5 \times 5 = 25 \equiv 4 \pmod 7.

4. 97=2×35+2797 = 2 \times 35 + 27; 35=27+835 = 27 + 8; 27=3×8+327 = 3 \times 8 + 3; 8=2×3+28 = 2 \times 3 + 2; 3=2+13 = 2 + 1. Back-substituting: 1=97×13+35×(36)1 = 97 \times 13 + 35 \times (-36). So 35×(36)1(mod97)35 \times (-36) \equiv 1 \pmod{97}: the inverse of 3535 is 3661(mod97)-36 \equiv 61 \pmod{97}.

5. aa is invertible modulo nn exactly when gcd(a,n)=1\gcd(a, n) = 1: Bézout provides au+nv=1au + nv = 1, i.e. au1au \equiv 1; conversely an inverse forces the gcd to divide 11.

6. 010+39+08+67+46+05+64+13+52+21=132=12×110(mod11)0{\cdot}10 + 3{\cdot}9 + 0{\cdot}8 + 6{\cdot}7 + 4{\cdot}6 + 0{\cdot}5 + 6{\cdot}4 + 1{\cdot}3 + 5{\cdot}2 + 2{\cdot}1 = 132 = 12 \times 11 \equiv 0 \pmod{11}: valid.

7. The sum changes by wdwd with 1w101 \leq w \leq 10 and 1d91 \leq \abs d \leq 9: since 1111 is prime and divides neither factor, it cannot divide the product (Theorem 29.11 / Proposition 29.14): the changed sum is never again 0\equiv 0: every single-digit error trips the alarm.

8. Swapping adjacent digits a,ba, b (weights w+1,ww + 1, w) changes the sum by (w+1)b+wa(w+1)awb=ba≢0(w+1)b + wa - (w+1)a - wb = b - a \not\equiv 0 for aba \neq b: detected. The secret is the primality of 1111: modulo 1010, products like 5×25 \times 2 vanish with neither factor zero, so a weight-55 error of ±2\pm 2 (or an unlucky transposition) could slip through.

9. Weighted sum of the twelve digits: 119119; the check digit must complete it to a multiple of 1010: 11 (full code 9782940199051978\,2940199\,051). EAN misses adjacent transpositions with 2(ab)0(mod10)2(a - b) \equiv 0 \pmod{10}, i.e. ab=5\abs{a - b} = 5: swapping a 22 and a 77, say, passes unseen — the price of the friendly modulus 1010.

10. Doubling every second digit from the right and folding (16716 \to 7, etc.), the sum comes to 800(mod10)80 \equiv 0 \pmod{10}: the test card validates.

11. With a prime modulus every weight is invertible, so all single errors and all adjacent transpositions are caught — ISBN’s luxury; mod-1010 schemes keep human-friendly digits and accept a short blind spot.

12. 210=1024=3×341+11(mod341)2^{10} = 1024 = 3 \times 341 + 1 \equiv 1 \pmod{341}, hence 2340=(210)3412^{340} = \left(2^{10}\right)^{34} \equiv 1. Yet 341=11×31341 = 11 \times 31 is composite: it passes Fermat’s test at base 22 while being no prime. Moral: Fermat’s congruence is necessary, not sufficient — primality testing needs sharper tools (and gets them, in the university volumes).

13. 3d1(mod20)3d \equiv 1 \pmod{20}: d=7d = 7 (21=20+121 = 20 + 1).

14. c=43=6431(mod33)c = 4^3 = 64 \equiv 31 \pmod{33}.

15. 31231 \equiv -2: (2)7=128(-2)^7 = -128, and 128+4×33=4-128 + 4 \times 33 = 4: the ciphertext decrypts to m=4m = 4. The lock turns.

16. Modulo 33: if 3m3 \nmid m, m21m^2 \equiv 1 (Fermat), so m21=m(m2)10mm^{21} = m \cdot \left(m^2\right)^{10} \equiv m; if 3m3 \mid m, both sides are 0\equiv 0. Modulo 1111: m101m^{10} \equiv 1 or 11m11 \mid m, and m21=m(m10)2mm^{21} = m \cdot \left(m^{10}\right)^2 \equiv m. Both 33 and 1111 divide m21mm^{21} - m, and being coprime their product 3333 does too (Gauss): m21m(mod33)m^{21} \equiv m \pmod{33}. The exponent ed=21=1+20ked = 21 = 1 + 20k was built so that both Fermat exponents (22 and 1010, dividing 2020) disappear.

17. Multiplying two 300300-digit primes takes a microsecond; recovering them from their product defeats every known algorithm and all the world’s computers — the lock is a one-way street. (Our n=33n = 33 is the street at toy scale, walkable in both directions.)

18. Testing residues (or building with Bézout): n8(mod15)n \equiv 8 \pmod{15}: the counts 8,23,38,53,8, 23, 38, 53, \dots Uniqueness modulo 1515: two solutions differ by a multiple of 33 and of 55, hence of 1515 (33 and 55 coprime, Gauss). The general with 10001000 soldiers announces “88” by three quick line-ups — the ancient headcount trick.

19. 101(mod9)10 \equiv 1 \pmod 9 gives 10k110^k \equiv 1, so dk10kdk\sum d_k 10^k \equiv \sum d_k: a number and its digit sum are congruent modulo 99 (and modulo 33). And 101(mod11)10 \equiv -1 \pmod{11} gives dk10k(1)kdk\sum d_k 10^k \equiv \sum (-1)^k d_k: the alternating rule. Two childhood rules, one line each.

20. Congruences turned remainders into an arithmetic (Part I); Bézout minted the inverses that solve linear congruences and RSA’s dd (questions 4, 13); Fermat’s little theorem opened and closed the lock (questions 15–16); gluing coprime moduli counted soldiers and finished the proof (questions 16, 18). Verdict on Hardy: the purest theorem he knew now guards every purchase — purity, given time, is the most applicable thing there is.