University Mathematics — Year 1 · Bachelor Year 1
6Integer Arithmetic
Arithmetic — the study of divisibility in — was begun in the High School volume. This chapter rebuilds it completely from the Euclidean division, with full proofs: greatest common divisor and the Euclidean algorithm, Bézout’s identity and Gauss’s lemma, prime factorization, and the calculus of congruences up to Fermat’s little theorem. Beyond its own charm, this material is the model that Chapter 8 imitates for polynomials.
6.1 Divisibility and Euclidean division
Definition 6.1 (Divisibility)
For , divides (written ) when for some . Basic consequences: if and then for all ; if and then ; and together with force .
Theorem 6.2 (Euclidean division)
For all and , there is exactly one pair with
Proof. Existence. The set is a nonempty subset of (take : ). Let be its least element. If , then would be a smaller element of : contradiction. So .
Uniqueness. If with , then and : the multiple of in the left-hand side must be , so and . ∎
Example 6.3 (Positional numeration by repeated division)
Write in base . Divide repeatedly by , keeping the remainders:
Reading the remainders from last to first: . Check: . The uniqueness of Euclidean division is exactly what makes each digit forced: at every step the remainder is the only integer in congruent to the current value mod , so base- writing is unique — the fact silently used whenever the weekend problem manipulates “the digits of in base ”.
6.2 Greatest common divisor
Theorem 6.4 (Subgroups of ; existence of the gcd)
Proof. (1) Let be a subgroup (nonempty, stable under subtraction; the formal definition is in Chapter 7, and only these two properties are used). If , take . Otherwise contains a nonzero element and its opposite, hence a smallest strictly positive element . Then . For , write with (Theorem 6.2); , and minimality of forces : . Uniqueness: is the least positive element of .
(2) contains and is stable under subtraction, so it is with (it contains or nonzero). Since , divides both. And if divides and , then divides every — in particular , since . This is the property announced (and it implies , so deserves the name greatest common divisor). ∎
Corollary 6.5 (Bézout’s identity)
For not both zero, there exist with
In particular (, the coprime case): and are coprime if and only if has a solution.
Proof. . For the equivalence: if , Bézout provides the solution; conversely forces every common divisor of to divide . ∎
Method 6.6 (Euclidean algorithm, extended)
To compute (): divide ; then (common divisors of and of coincide, since ); iterate until the remainder is ; the last nonzero remainder is the gcd. Running the divisions backwards (or maintaining the coefficients on the way down) produces a Bézout pair .
Example 6.7
: ; ; ; ; . So . Backwards:
Check: , .
Theorem 6.8 (Gauss’s lemma and consequences)
Let .
- (Gauss’s lemma) If and , then .
- If , and , then .
- If , then .
Proof. (1) Bézout: . Multiply by : . Both terms are divisible by (the second because ), so .
(2) Write ; from and , point (1) gives , so .
(3) and . Multiply the two relations:
a Bézout relation between and : by Corollary 6.5, . ∎
Example 6.9 (Solving a linear Diophantine equation)
Find all with . First, the existence test: divides , so solutions exist (if the gcd did not divide the right-hand side, the left side would always be a multiple of it and there would be none). Divide through: . A particular solution is visible: . For the general one, subtract: , so , and Gauss’s lemma () gives : , then . Conversely every such pair works:
The pattern is general: one particular solution plus the integer multiples of — the same “particular plus homogeneous” structure as in Chapter 5, with Gauss’s lemma playing the uniqueness role.
Definition 6.10 (Least common multiple)
is the generator in of the subgroup : it is a common multiple of and that divides every common multiple, and for ,
Example 6.11 (Alignment problems are lcm problems)
Two meshed gears have and teeth. After how many teeth of common motion do they return to their initial position together? The configuration repeats when the number of elapsed teeth is a common multiple of and ; the first time is
teeth — that is, turns of the large gear and of the small one ( and ). Note the practical route: compute the gcd first (Euclid: , ), then divide — never build the lcm by listing multiples. Every periodic-coincidence question (gears, planetary alignments, repeating decimals meeting) reduces to this one computation.
6.3 Prime numbers
Definition 6.12
An integer is prime when its only positive divisors are and . For prime and : either , or . Consequently (Theorem 6.8), Euclid’s lemma holds: if then or .
Remark 6.13 (Testing primality by trial division)
If with , then , so : a composite always has a prime divisor . Hence to test whether is prime it suffices to try the primes up to . For : , and is divisible by none of (odd, digit sum , does not end in or , ): prime, after six divisions instead of two hundred. The barrier is a genuine threshold: crossing it efficiently for hundred-digit numbers requires the modern primality tests grown out of Theorem 6.23.
Theorem 6.14 (Euclid)
There are infinitely many primes.
Proof. Every integer has a prime divisor: its smallest divisor is prime (a proper factorization of it would produce a smaller divisor of ). Now suppose were all the primes, and let . Some prime divides ; but also divides , so — absurd. ∎
Theorem 6.15 (Fundamental theorem of arithmetic)
Every integer is a product of primes, and the factorization
is unique.
Proof. Existence by strong induction (Theorem 1.12): is prime; for , either is prime, or with , and the induction hypothesis factors and .
Uniqueness. Suppose (primes listed with repetition, say), and induct on . If the left side is , forcing (a nonempty product of primes exceeds ). For : the prime divides , so by Euclid’s lemma either or ; iterating, divides some . But is prime and : necessarily . Cancel this common factor (legitimate: is an integral domain) to get
(the hat marking omission), an equality of shorter products; the induction hypothesis says the two lists and coincide up to order, hence so did the original ones. The exponent form groups equal primes. ∎
Proposition 6.16 (Valuations)
For prime and , write for the exponent of in the factorization of (with if ). Then
Proof. The first identity holds because the factorizations multiply and the factorization of is unique. If , write and apply it. Conversely, if all , the integer satisfies . The gcd formula: the integer divides both by the criterion, and every common divisor has for all , so ; same reasoning for the lcm with . ∎
Example 6.17 (Squares and cubes through valuations)
An integer is a perfect square if and only if every is even (if , then ; conversely halve every exponent). Likewise for cubes with multiples of . Thus is not a square ( is odd) and not a cube (); the smallest positive integer such that is a cube is found by topping up each exponent to the next multiple of :
The insight: multiplicative questions (squares, cubes, divisors, gcd, lcm) become coordinatewise questions on the exponent vectors — unique factorization is the statement that these coordinates exist and are well defined.
6.4 Congruences
Definition 6.18
For : when . This is an equivalence relation compatible with addition and multiplication: if and (mod ), then , , and for .
Example 6.19 (Casting out nines)
Compatibility with and is a checking device as old as commerce. Since , every integer is congruent mod to its digit sum (proved as Exercise 6.2). To check the claim : digit sums give and , so the product must be ; and indeed . The check passes (and the product is in fact correct). Had someone reported , the digit sum would convict them instantly. The test is one-sided — it catches an error unless the error is itself a multiple of — which is exactly the pseudoprime lesson of Example 6.24 in miniature: congruence checks refute, they do not certify.
Proposition 6.20 (Invertibility mod )
is invertible mod (i.e. for some ) if and only if . The inverse is then unique mod and computed by the extended Euclidean algorithm.
Proof. means for some : a Bézout relation, which exists iff (Corollary 6.5). Uniqueness: if , then . ∎
Example 6.21 (Inverting modulo )
Since , the class of is invertible mod . Extended Euclid:
then backwards:
Hence , i.e. ; check: . With the inverse in hand, any congruence is solved in one multiplication: . This mechanical inversion is the workhorse of modular arithmetic — and of the public-key protocols mentioned in Remark 6.27, where the moduli have hundreds of digits but the algorithm is exactly this one.
Example 6.22 (When the coefficient is not invertible)
Solve . Here , so is not invertible mod — but the equation is still tractable. The congruence says ; dividing the whole relation by (divisor of all three ingredients), it is equivalent to , i.e.
Now and (), so : the solutions are — four classes mod , matching the gcd. (Had the right side not been divisible by , say , there would be no solution at all: the left side is always .) General shape: is solvable iff , and then has exactly solution classes — divide everything by the gcd and invert.
Theorem 6.23 (Fermat’s little theorem)
Let be prime. For every :
and if , then .
Proof. First, for , the binomial coefficient is divisible by : indeed and divides but is coprime to (all factors are ), so Gauss’s lemma gives .
Now prove for by induction. True for . If , then by the binomial theorem
all middle terms vanishing mod . For , apply the result to and separate (where ) from odd (where ). Finally, if , multiply by an inverse of mod (Proposition 6.20). ∎
Example 6.24 (Fermat’s converse fails: )
Fermat’s little theorem gives a cheap compositeness test: if for some coprime to , then is not prime. Could the test also certify primality? No: take , composite, and . Since ,
the composite passes Fermat’s test for the base (it is the smallest such pseudoprime). The base unmasks it (), and practical primality testing therefore runs the test on several bases, plus refinements — the industrial versions of this idea are what certify the large primes of Remark 6.27. Moral: an implication and its converse live separate lives (Remark 1.10), even for theorems.
Example 6.25 (Practical congruence computations)
What is the remainder of mod ? By Fermat, . Since :
The remainder is . The strategy: reduce the exponent modulo the order provided by Fermat, then reduce intermediate powers at every step.
Remark 6.26 (Common pitfalls in arithmetic)
- Dividing a congruence. From one may not conclude unless : but . The correct general rule divides the modulus too: .
- Misusing Euclid’s lemma. implies or only for prime (or coprime to one factor): yet divides neither factor.
- Coprime is a relation, not a property. “ and are coprime” is true though neither is prime; “pairwise coprime” is stronger than “globally coprime” ( but no pair is coprime).
- Exponents do not live mod . In , the exponent may only be reduced modulo the order of (for instance when Fermat applies), never modulo : is , not — the reduction that works is the one Example 6.25 performs.
Remark 6.27 (Where this chapter is used)
This chapter is a template as much as a toolbox. The whole chain — Euclidean division, gcd, Bézout, Gauss, unique factorization — is replayed verbatim for polynomials in Chapter 8, where “degree” plays the role of absolute value; comparing the two chapters side by side is the best way to understand both. The congruence calculus becomes the ring in Chapter 7, whose invertible elements (Proposition 6.20) form the first nontrivial example of a group of units. Valuations return in the weekend problem below (Legendre’s formula) and power the irrationality proofs of Chapter 10. Beyond this volume, Bézout inversion mod is the engine of public-key cryptography, and Fermat’s little theorem is the grandfather of the primality tests that certify the large primes used there.
Remark 6.28 (Interlude: as a template)
Step back from the individual theorems and observe the architecture of the chapter: one tool (Euclidean division) produced a classification (subgroups ), which produced an existence theorem (gcd, Bézout), which produced a divisibility calculus (Gauss), which produced unique factorization — each floor resting only on the one below. The same building will be erected twice more in this volume with different ground floors: in Chapter 8, where division by degree replaces division by size and everything above repeats verbatim; and, in miniature, inside every of Chapter 7, where invertibility questions (this chapter’s Proposition 6.20) become structural statements about rings and fields. Recognizing an argument as “the -argument, transplanted” is the fastest way to learn those chapters — and the first taste of algebra’s core habit, proving theorems about axioms rather than about objects.
6.5 Exercises
Exercise 6.1 ★
Compute by the Euclidean algorithm, and a Bézout pair for it.
Solution
Solution of Exercise 6.1.
; ; ; ; . So . Backwards:
Check: and ; difference . Bézout pair: for .
Exercise 6.2 ★
Prove the divisibility rules in base : an integer is congruent mod to the sum of its digits, and mod to the alternating sum of its digits. What is mod and mod ?
Solution
Solution of Exercise 6.2.
Since : , so . Since : , so the integer is congruent to the alternating sum mod (starting from the units digit with sign ).
: digit sum . Alternating sum from the units: , so the number is .
Exercise 6.3 ★
Solve in : (extended Euclid).
Solution
Solution of Exercise 6.3.
Euclid: ; ; ; ; ; . Backwards:
So : the solutions are . (Check: .)
Exercise 6.4 ★
Find all pairs with ; then all pairs with .
Solution
Solution of Exercise 6.4.
: Euclid gives , , , and backwards
Particular solution . General solution of the homogeneous equation : , (since and force — Gauss’s lemma). Hence
For the right-hand side , multiply the particular solution by : , .
Exercise 6.5 ★★
Prove that for : . (Use the valuation formulas of Proposition 6.16 and .)
Solution
Solution of Exercise 6.5.
For every prime , with and :
Two positive integers with the same valuation at every prime are equal (Proposition 6.16), so .
Exercise 6.6 ★★
Let and . Compute , , and the number of positive divisors of . (Prove the divisor-count formula .)
Solution
Solution of Exercise 6.6.
Valuations: ; .
Divisor count: a positive divisor of is exactly a choice with (Proposition 6.16); the choices are independent, so there are divisors. For : .
Exercise 6.7 ★★
Prove that is irrational for every prime , using valuations: compare of both sides of .
Solution
Solution of Exercise 6.7.
Suppose with , i.e. . Apply : is odd, while is even. An integer cannot have an odd and an even -valuation at once: contradiction. So .
Exercise 6.8 ★★
(Chinese remainder problem) Find all integers with
Prove along the way that for coprime , the pair of congruences , always has a solution, unique mod .
Solution
Solution of Exercise 6.8.
General fact. With , Bézout gives . Set . Then and similarly : existence. If and are two solutions, and divide , so (Theorem 6.8 (2)): uniqueness mod .
Numerically: , : . So . Check: ; . Solutions: .
Exercise 6.9 ★★
Compute mod , and the last two decimal digits of (mod : use Exercise 6.8).
Solution
Solution of Exercise 6.9.
Mod : Fermat gives , and , so .
Last two digits of : work mod and mod . Mod : , so . Mod : , so and . By the Chinese remainder theorem (Exercise 6.8), : the last two digits are .
Exercise 6.10 ★★★
For , prove that . Hint: show first that the remainder of mod is where is the remainder of mod ; then follow the Euclidean algorithm.
Solution
Solution of Exercise 6.10.
Write , . Then
and divides . So mod , , and since , this is the Euclidean remainder.
Therefore the Euclidean algorithm on the pair mirrors, exponent by exponent, the algorithm on : each division step replaces by upstairs and by downstairs. The algorithm upstairs terminates at , so downstairs it terminates at .
Exercise 6.11 ★★★
(Wilson’s theorem) Let be a prime. Prove that
by pairing each factor of with its inverse mod and identifying the self-paired factors (solve first). Check the converse: if is not prime, then .
Solution
Solution of Exercise 6.11.
First solve : , so by Euclid’s lemma or .
In the product , every factor is invertible mod , and its inverse is again one of the factors (Proposition 6.20). Pair each with : the pairs multiply to , except that self-paired factors (, i.e. ) stand alone — and these are exactly and . Hence
(For : ; the pairing argument degenerates but the result holds.)
Converse. Let be composite, with . If , both appear as distinct factors of , so and . If (i.e. ): for , both and are , so , same conclusion; for , .
Exercise 6.12 ★★★
(Fermat numbers) For , let .
- Prove that for (induction).
- Deduce that the Fermat numbers are pairwise coprime.
- Deduce a second proof, independent of Theorem 6.14, that there are infinitely many primes.
Solution
Solution of Exercise 6.12.
Induction. For : . Assuming :
- Let and . By (1), divides , so divides both and , hence divides . But every Fermat number is odd, so .
- Each has a prime divisor (Theorem 6.14’s first step). If , then , since a common prime would divide . The map is therefore injective from into the primes: there are infinitely many primes.
6.6 Problem: Legendre’s formula and Kummer’s carries
Problem 6.1
How many zeros end the decimal writing of — and, deeper, what is the exact power of a prime dividing , or dividing a binomial coefficient? The complete answers are two gems of elementary arithmetic: Legendre’s formula , with its digital avatar , and Kummer’s theorem: counts the carries when adding and in base . This problem proves both, checks them against each other numerically, and harvests the classical consequences — trailing zeros, the parity of Pascal’s triangle, and a first bound in the direction of the prime number theorem. Throughout, is a prime, is the integer part, and denotes the sum of the digits of written in base .
Part I — Floors, valuations, and Legendre’s formula.
- Warm-up: compute and read off its number of trailing zeros; compute and directly from the factorization of each factor .
- Prove that for and , .
- Prove that for all , with equality whenever .
- Show that the number of multiples of in is .
Prove Legendre’s formula: for every ,
(a finite sum: the terms vanish once ). Count, for each , the factors of divisible by : each contributes exactly one unit per level it reaches.
Part II — The digital form and trailing zeros.
- Compute and , and conclude: how many zeros end ?
Prove the digital form of Legendre’s formula: writing in base ,
- Two consequences for : show that never divides , and that divides exactly when is a power of .
- Bound the defect: show , so that : in the long run, a proportion of one factor accrues per unit.
- Let be the number of trailing zeros of . Show , deduce that skips the value entirely (compute and ), and prove that no factorial ends in exactly five zeros.
Part III — Kummer’s theorem.
Prove that for all , and deduce from Legendre’s formula that
a sum of terms each equal to or .
- Prove Kummer’s theorem: the -th term of that sum equals exactly when the addition of and in base produces a carry into position ; hence is the total number of carries. (Write and with and inspect .)
Deduce that for :
by counting the carries in the addition . (In particular for : the key step of Theorem 6.23, recovered.)
- Prove that . Deduce that the central binomial coefficient is always even, and that exactly when is a power of .
- Show, using Vandermonde’s identity (Exercise 2.7) and question 13, that for every prime .
- Compute twice: once by Kummer (write in base and count the carries in ), once by Legendre’s digital form (compute and ); check that both give the same value.
Part IV — The parity of Pascal’s triangle, and a prime-density bound.
- Prove the digit criterion: is odd if and only if every binary digit of is at most the corresponding digit of . State and prove the analogous criterion for in base .
- Deduce that row of Pascal’s triangle contains exactly odd entries; verify on rows and .
- Deduce that all interior entries () are even if and only if is a power of .
- Prove that every prime power dividing is at most : if then . (How many nonzero terms can the sum of question 11 have?)
Deduce that divides , and combine with the lower bound (which you will prove: the central entry is the largest of the entries of row ) to obtain
the common multiples of the first integers grow exponentially — a first quantitative glimpse of the abundance of primes.
Part V — Synthesis.
- Find the smallest such that ends in at least zeros. (Estimate , then adjust using the exact formula.)
- One last cross-check: show that does not divide , first by writing in base and checking that the addition is carry-free, then by computing and with Legendre’s formula.
- Where exactly did the problem use: (i) unique factorization; (ii) the Euclidean-division decomposition ; (iii) a counting argument from Chapter 2? One sentence each.
- Synthesis, in a short paragraph: Legendre’s formula turns a divisibility question into digit arithmetic, and Kummer’s theorem reads the answer off the carries of one addition — comment on this translation, on the checks of question 16, and on what the bound of question 21 suggests about primes (the full statement, the prime number theorem, is far beyond this volume; the polynomial analogue of this chapter’s toolkit is Chapter 8).
Solution
Solution of Problem 6.1.
1. : two trailing zeros. Valuations factor by factor: powers of come from , totaling ; powers of from and : . Trailing zeros , consistent.
2. Write the Euclidean division , . Then with , so .
3. Let (swap if needed) and write , with . Then , so . If , the parenthesis is : the valuation is exactly .
4. The multiples of in are where is the largest integer with , i.e. .
5. By unique factorization, . Count differently: each contributes , so
by question 4 — Legendre’s formula. The sum is finite: terms with vanish.
6. (divisions by ); . Trailing zeros of : each zero consumes one and one , so there are of them.
7. With , question 2 gives (truncate the base- expansion). Summing over and exchanging the two finite sums:
8. For : . Since has , always : . And iff iff is a power of .
9. has base- digits, each at most , so . Substituting in question 7:
and dividing by : .
10. : the count of trailing zeros jumps by at each multiple of and is constant in between. and : at the count jumps from straight to (), and since is nondecreasing with before and after, the value is never attained: no factorial ends in exactly five zeros.
11. Write : , and makes the last floor or . Then, by Legendre applied three times,
a finite sum of s and s (apply the first claim to , ).
12. Fix and write , with (Euclidean division: is the number formed by the low digits of ). Then
which is if and otherwise. But says precisely that adding the low digits of and overflows into position — a carry into position in the schoolbook addition algorithm. Summing over : is the number of carries in the base- addition . (Kummer, 1852.)
13. Apply Kummer to , , sum . Let , so the base- digits of at positions are and the digit at position is nonzero. The digits of below position are too (). At position , the two nonzero digits must sum to (result digit ): one carry; at each position , digits plus the incoming carry sum to (result digit again): the carry propagates. Total: carries, so . For : for , the divisibility used in Theorem 6.23.
14. By the digital form (question 7), using (appending a zero digit):
is always even, and (i.e. ) exactly when , i.e. when is a power of .
15. Vandermonde with : . For , (question 13), so ; the end terms give : .
16. Base : , digits (low to high) , so ; and , digits , so . Kummer: add in base : position : , digit carry ; position : , digit carry ; position : , digit carry ; position : , no carry; position : ; position : , digit carry ; position : carry lands: digit . Four carries: . Legendre: and , so . The two computations agree — and the addition digits reproduce , as they must.
17. By Kummer (, , ): is odd iff the addition in base has no carry, iff at every position the digits satisfy ; in that case for all . Conversely, if for all , then the number with digits is and the addition is carry-free. Same proof in base : iff every base- digit of is at most the corresponding digit of .
18. Counting the whose digits obey : each digit of is chosen independently among values, giving choices; in base this is . Row : odd entries — indeed has odd entries only at the ends. Row : — indeed .
19. All interior entries even the row has exactly odd entries (the two ends always are odd) is a power of .
20. In question 11’s sum, the -th term vanishes as soon as (all three floors are then equal, indeed the first is when ; more simply each term is ). Hence at most terms are nonzero, each worth : , i.e. .
21. For every prime , (the largest power of not exceeding appears among ). Question 20 with gives for every : by Proposition 6.16, . For the size: the ratio exactly for , so the central entry is the largest of the entries of row , whence . Combining:
If there were few primes below , the lcm could not be this large: exponential growth of the lcm is a quantitative trace of the abundance of primes.
22. , so aim near : . Step up by multiples of : , , and
Since is constant between multiples of and , the smallest with at least trailing zeros is .
23. Base : , digits (low to high) . Adding : position : , no carry; position : ; position : , no carry. Carry-free, so by Kummer : . Legendre agrees: and , so .
24. (i) Unique factorization underlies the very definition of and its additivity, hence Legendre’s formula and every divisibility conclusion (Proposition 6.16). (ii) Euclidean division produced the truncation identity of question 2 and the split that isolates the carry (question 12). (iii) Counting: the multiples-of- count (question 4), the digit-choice product (question 18), and the row-sum bound (question 21) are all Chapter 2-style arguments.
25. Legendre converts “what power of divides ” into base- digit arithmetic; Kummer compresses the answer for binomial coefficients into the carries of a single addition — divisibility, seemingly a global property of huge numbers, is read off locally, digit by digit. Question 16 is the paradigm: four carries, computed by hand, determine the exact power of in a number with hundreds of digits. And question 21 shows the same circle of ideas brushing against deep waters: an exponential lower bound for is a first, fully elementary step toward the prime number theorem, whose proof lies far beyond this volume. The entire toolkit — division, gcd, valuations — is replayed for polynomials in Chapter 8, where the analogue of a digit expansion is expansion in powers of .