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 . We say divides , written , if there exists with . We also say is a multiple of .
Proposition 29.2
If and , then divides every integer combination (). If and with , then . If and , then .
Proof. Write , : then . The other points follow from with when . ∎
Theorem 29.3 (Euclidean division)
Let and . There exists a unique pair such that
is the quotient and the remainder.
Proof. Existence. The set of multiples of not exceeding has a largest element (it is nonempty and bounded above); set . By maximality, , so . Uniqueness. If with , then and : a multiple of of absolute value less than must be , so and . ∎
29.2 Congruences
Definition 29.4 (Congruence)
Let . Two integers are congruent modulo , written , if — equivalently, if and have the same remainder in the Euclidean division by .
Proposition 29.5 (Compatibility with operations)
If and , then
Proof. divides , and is also a multiple of . The power rule follows by induction from the product rule. ∎
Method 29.6 (Computing powers modulo )
To compute , reduce the base modulo , then look for a small power of congruent to , and use it to collapse the exponent. For instance : since and ,
29.3 GCD, Bézout and Gauss
Definition 29.7 (GCD)
Let be integers, not both zero. The greatest common divisor is the largest integer dividing both and . When , and are said to be coprime.
Proposition 29.8 (Euclid’s algorithm)
If (), then . Iterating the Euclidean division therefore computes : the gcd is the last nonzero remainder.
Proof. Any common divisor of and divides (Proposition 29.2), hence is a common divisor of and ; and conversely, since . 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
: ; ; ; . Hence .
Theorem 29.10 (Bézout’s identity)
Let be integers, not both zero, and . There exist such that
In particular, and are coprime if and only if for some integers .
Proof. Run Euclid’s algorithm backwards: each remainder is an integer combination of the previous two, and the initial data are combinations of themselves; by descending substitution, the last nonzero remainder is an integer combination of and . (In Example 29.9: .)
For the equivalence: if , Bézout provides ; conversely, any common divisor of and divides , forcing . ∎
Theorem 29.11 (Gauss’s lemma)
Let . If and , then .
Proof. Bézout gives ; multiply by : . Both terms of the left side are multiples of (the second because ), hence so is . ∎
Corollary 29.12
If , and , then .
Proof. Write . From and , Gauss gives , say ; then . ∎
29.4 Prime numbers
Definition 29.13 (Prime)
An integer is prime if its only positive divisors are and .
Proposition 29.14
Every integer has a prime divisor; if is not prime, it has a prime divisor . If a prime divides a product , then or (Euclid’s lemma).
Proof. The smallest divisor of is prime (any proper divisor of would be a smaller divisor of ). If is composite with , then , so . For Euclid’s lemma: if , then (the only divisors of are and ), and Gauss’s lemma gives . ∎
Theorem 29.15 (Euclid)
There are infinitely many primes.
Proof. Given any finite list of primes, consider . Some prime divides ; but no divides (the remainder is ), so is a prime not in the list. No finite list exhausts the primes. ∎
Theorem 29.16 (Fundamental theorem of arithmetic)
Every integer is a product of primes, and this factorization is unique up to the order of the factors:
Proof. Existence, by strong induction: prime is its own factorization; otherwise with , and both factor by the induction hypothesis. Uniqueness: suppose (primes, with repetitions allowed). By Euclid’s lemma, divides some , and being prime, ; cancel and repeat. The two factorizations match term by term. ∎
Theorem 29.17 (Fermat’s little theorem)
Let be prime and with . Then
For every (no coprimality assumed), .
Proof. Consider the integers modulo . None is (if with , Euclid’s lemma forces , impossible), and they are pairwise distinct modulo (if , then , so , so ). Hence, modulo , they are the numbers in some order. Multiplying all congruences:
Since divides none of , repeated use of Euclid’s lemma allows cancelling , leaving . The second form follows by multiplying by (and is trivial when ). ∎
Example 29.18 (Application to cryptography)
Fermat’s theorem makes exponentiation modulo reversible when the exponents are chosen suitably — the heart of the RSA cryptosystem. With large primes and , one publishes and an exponent ; encryption is . Decrypting requires an exponent with , which only someone knowing and can compute — and recovering from 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 by , and of by .
Solution
Solution of Exercise 29.1.
, so : quotient , remainder . For : (indeed and ): quotient , remainder (the remainder must lie in , so it is not ).
Exercise 29.2 ★
What is the remainder of modulo ? (What is the last digit of ?)
Solution
Solution of Exercise 29.2.
Modulo : . Hence : the last digit of is .
Exercise 29.3 ★
Using Euclid’s algorithm, compute , and find integers with .
Solution
Solution of Exercise 29.3.
Euclid: ; ; . So .
Back-substitution: . Thus , : .
Exercise 29.4 ★
Show that for every , is congruent to or modulo . Deduce that an integer is never a sum of two squares.
Solution
Solution of Exercise 29.4.
Every integer is or , and squaring: , , , . So or . A sum of two squares is then congruent to , or , i.e. to , or — never to .
Exercise 29.5 ★★
Show that for all , is divisible by .
Solution
Solution of Exercise 29.5.
Divisibility by : among and , one is even. Divisibility by : if , then ; if , then ; if , then . In all cases divides the product. Since , Corollary 29.12 gives . (This also re-proves that , the sum of squares of Exercise 20.1, is an integer.)
Exercise 29.6 ★★
Solve in the congruence . (Hint: find the inverse of modulo .)
Solution
Solution of Exercise 29.6.
We look for the inverse of modulo : testing (or Bézout), . Multiplying the congruence by :
The solutions are the integers , . (Check: .)
Exercise 29.7 ★★
Solve in the Diophantine equation
then describe all solutions of .
Solution
Solution of Exercise 29.7.
, so solutions exist. Euclid: ; ; . Back-substituting: . Hence : the particular solution .
General solution of : subtracting the particular relation, ; since , Gauss gives , so and then , (all of which check).
For , multiply the particular solution by : , and the same reasoning gives
(E.g. : , ; indeed .)
Exercise 29.8 ★★
Show that is irrational, using the uniqueness of prime factorization (compare the exponent of on both sides of ).
Solution
Solution of Exercise 29.8.
Suppose with ; then . In the prime factorization of a square, every exponent is even; so the exponent of in is even, while in it is odd (one more than an even number). Two factorizations of the same integer with different exponents of contradict the uniqueness in Theorem 29.16. Hence no such fraction exists: .
Exercise 29.9 ★★★
Let be a prime.
- Show that for , divides . (Hint: use , Exercise 27.7, and Gauss’s lemma.)
- Deduce, by induction on , another proof of Fermat’s little theorem in the form .
Solution
Solution of Exercise 29.9.
1. From , divides . For , and prime give , so Gauss’s lemma yields .
2. Induction on . For : . Assume . By the binomial theorem,
all middle terms vanishing modulo by point 1. By the induction hypothesis, . This proves for all , and the case follows by writing for a suitable positive representative.
Exercise 29.10 ★★★
(Chinese remainder problem.) Find all integers such that
(Hint: solve the first two conditions, then incorporate the third; Bézout coefficients help.)
Solution
Solution of Exercise 29.10.
and : write ; then , i.e. . The inverse of modulo is (), so , say , and : the first two conditions mean .
Adding : , and , so , say . Hence :
(Check: .)
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.
- Compute ; then the last digit of (find the cycle of powers of modulo ).
- Fast exponentiation (Method 29.6): compute (start from ).
- Solve .
- Run Euclid’s algorithm on , back-substitute to find integers with , and deduce the inverse of modulo .
- State precisely when is invertible modulo , and which theorem delivers the inverse.
Part II — Check digits.
- ISBN-10: the ten digits of a book code must satisfy . Verify the real ISBN .
- Prove that the ISBN scheme detects every single-digit error: if one digit changes by , the weighted sum changes by with — why can this never be (Theorem 29.11)?
- Prove it also detects every transposition of two adjacent (distinct) digits. Then explain the design secret: what property of made both proofs work, and what could go wrong with modulus ?
- EAN-13 barcodes weight the digits modulo . Compute the check digit completing . Which adjacent transpositions does EAN fail to detect? (When is ?)
- Credit cards use Luhn’s scheme: from the right, double every second digit (subtracting when the double exceeds ), sum everything, and require a multiple of . Verify the test number .
- In one sentence: what did the prime modulus buy ISBN that EAN and Luhn, chained to , cannot have?
Part III — Fermat’s lock.
- A trap before the treasure: compute , deduce — and then factor . What does this example (a Fermat pseudoprime) say about using Fermat’s little theorem as a primality test?
- RSA in miniature: take , , so and ; the public exponent is . Find the private exponent with (question 4’s method).
- Encrypt the message : compute .
- Decrypt: compute (use ) and recover the message.
- Why decryption always works: show that both modulo and modulo (Fermat’s little theorem in each world), and conclude modulo (Theorem 29.11 glues the two congruences). Where did ’s special form enter?
- The lock’s safety: everyone knows and ; recovering requires , hence the factors of . Our factors at sight — why does the same scheme, with of six hundred digits, protect the world’s banks? (One sentence on the asymmetry between multiplying and factoring.)
Part IV — Classics.
- The old Chinese soldier count (compare Exercise 29.10): a number of soldiers leaves remainder when ranked by and remainder when ranked by . Find all possible counts, and explain why the answer is unique modulo .
- One-line proofs at last: from , prove that every number is congruent to its digit sum modulo ; from , derive the alternating-sum rule for . (The Middle School volume proved these with explicit algebra — admire the compression.)
- 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. : . Powers of mod : , cycle of length ; : last digit of is .
2. , so and .
3. The inverse of modulo is (): .
4. ; ; ; ; . Back-substituting: . So : the inverse of is .
5. is invertible modulo exactly when : Bézout provides , i.e. ; conversely an inverse forces the gcd to divide .
6. : valid.
7. The sum changes by with and : since is prime and divides neither factor, it cannot divide the product (Theorem 29.11 / Proposition 29.14): the changed sum is never again : every single-digit error trips the alarm.
8. Swapping adjacent digits (weights ) changes the sum by for : detected. The secret is the primality of : modulo , products like vanish with neither factor zero, so a weight- error of (or an unlucky transposition) could slip through.
9. Weighted sum of the twelve digits: ; the check digit must complete it to a multiple of : (full code ). EAN misses adjacent transpositions with , i.e. : swapping a and a , say, passes unseen — the price of the friendly modulus .
10. Doubling every second digit from the right and folding (, etc.), the sum comes to : 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- schemes keep human-friendly digits and accept a short blind spot.
12. , hence . Yet is composite: it passes Fermat’s test at base 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. : ().
14. .
15. : , and : the ciphertext decrypts to . The lock turns.
16. Modulo : if , (Fermat), so ; if , both sides are . Modulo : or , and . Both and divide , and being coprime their product does too (Gauss): . The exponent was built so that both Fermat exponents ( and , dividing ) disappear.
17. Multiplying two -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 is the street at toy scale, walkable in both directions.)
18. Testing residues (or building with Bézout): : the counts Uniqueness modulo : two solutions differ by a multiple of and of , hence of ( and coprime, Gauss). The general with soldiers announces “” by three quick line-ups — the ancient headcount trick.
19. gives , so : a number and its digit sum are congruent modulo (and modulo ). And gives : 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 (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.