JB Math Club 26-27 · Lecture notes
Wilson’s, Fermat’s, and Euler’s Theorems
Modular Inverses
This lecture develops modular division and explains how factorials and large powers behave modulo an integer. The proofs use only congruences, divisibility, elementary counting, and prime factorization.
Route through the lecture. Modular inverses; Wilson's theorem; Fermat's theorem and its counting proofs; the totient function; Euler's theorem; constructions with many prime divisors.
1. Modular inverses and cancellation
We know that means . Throughout, a modulus satisfies , unless the definition of is being discussed. We write for the greatest common divisor. Two integers are coprime when this gcd is . A residue modulo can be represented by one of .
Example 1. When cancellation fails
Compare the congruences and . Can we cancel the coefficient of ?
Solution. Since , multiplying the first congruence by gives . In the second congruence both and work, although . In fact, is equivalent to .
The cancellation lemma
Lemma 1. If and , then .
Proof. The hypothesis says . No prime factor of divides . Consequently every prime power in the factorization of must divide , so . This proof uses only prime factorization, not modular inverses.
Multiplication rearranges the residues
Theorem 1. If , then represent all residues modulo , each exactly once. Thus has exactly one solution modulo , for every integer .
Proof. If , Lemma 1 gives . For , this means . There are distinct outputs and only possible residues, so every residue occurs. In particular, precisely one input gives the residue of .
The modular inverse
Definition. A modular inverse of modulo is an integer satisfying . Its residue class is denoted by . This notation refers to modular multiplication, not to the ordinary rational number .
Theorem 2. An inverse of modulo exists if and only if . When it exists, it is unique modulo , and the solutions of are .
Proof. For coprime , apply Theorem 1 to . Conversely, if is divisible by , a common divisor of divides both and , hence divides . Finally, multiply by the inverse. Every integer in the resulting residue class is a solution.
Example 2. Solving with an inverse
Solve .
Solution. The equality shows that . Therefore
Checking gives , which is divisible by . Also, is its own inverse modulo , because and .
Example 3. Finding an inverse by Euclid
Find the inverse of modulo , and solve .
Solution. Successive divisions give , , and . Work backwards:
Reducing modulo gives . Hence , and .
This backwards substitution is the extended Euclidean algorithm. More generally, Euclid produces integers with , an identity often called Bézout's identity. When the gcd is , reducing this equality modulo supplies an inverse.
Linear congruences with a common divisor
Theorem 3. Let . The congruence has a solution if and only if . If it does, it has exactly distinct solutions modulo .
Proof. A solution implies , so . If , divide the divisibility statement by :
The new coefficient and modulus are coprime, so the reduced congruence has one solution class . Its representatives modulo are , which are distinct. If , the reduced condition imposes no restriction, and all residue classes work.
Example 4. Dividing changes the modulus
Solve . What happens to ?
Solution. The gcd is . The first congruence reduces to , so . The second has no solution because .
2. Wilson's theorem
Residues that equal their inverses
Lemma 2. For an odd prime , the only nonzero residues satisfying are and . For , these are the same residue.
Proof. We have . Since is prime, it divides at least one factor. Thus or . Both work. Primality matters: modulo , all of have square congruent to .
Example 5. Pairing inverses modulo eleven
The inverse pairs among , excluding the two self-inverses, are
Each pair has product modulo . The unpaired residues are and . Thus .
The theorem and its converse
Theorem 4 (Wilson). For an integer , holds if and only if is prime. Here , and .
Proof for primes. Suppose first that is odd and prime. Every nonzero residue has a unique inverse. A residue that is not its own inverse pairs with a different residue, and that residue pairs back with it. Every such pair contributes . By Lemma 2, only and remain, so
For , directly .
Proof of the converse. If is composite, choose a proper divisor with . It occurs among the factors of . Hence . If also , then , which would force . This is impossible.
For instance, . In contrast, , because its factors include both and , and . It is unnecessary to prove that every composite modulus divides its preceding factorial; that stronger claim would fail for .
Problem 1. A factorial near a prime
Find the remainder when is divided by .
Solution. Wilson gives . Separate the final two factors:
Thus . Since is invertible,
Problem 2. A square root of minus one
Let be prime. Prove that has a square root modulo .
Solution. Put . Pair the factor in the lower half of the factorial with in the upper half. Then
Because , the integer is even. Wilson therefore gives .
For , , and . This is an existence argument with an explicit construction; it does not require a theory of quadratic residues.
3. Fermat's little theorem
A product that stays the same
Theorem 5 (Fermat). If is prime and , then . Equivalently, for every integer , we have .
Proof by rearranging residues. Multiplication by rearranges : the outputs are distinct by cancellation, and none is . Multiply all outputs:
The factorial is coprime to , so we may cancel it and obtain . Wilson is not needed for this cancellation. Multiplying by gives . If , that second congruence holds because both sides are . Conversely, when , cancel in to recover the first form.
For example, when , whereas holds for every integer . The latter form includes negative integers and zero.
Example 6. Reducing a large exponent
Find .
Solution. Since , Fermat reduces the task to . Successive squaring gives , , and .
The base is reduced modulo ; the exponent is reduced modulo . These are different operations. The exponent reduction works because .
Problem 3. A large composite number
Prove that is composite.
Solution. The nearby prime fits both terms: the first exponent is , and the second base is modulo . Fermat gives
The number is positive and greater than , so this divisor proves compositeness.
4. Two more proofs of Fermat's theorem
Example 7. Binary words of length five
A word is an ordered string of symbols. There are words of length using . Exactly two are constant: and . Group each remaining word with all its cyclic rotations. For example,
We count words with a designated first position. Rotation puts different words into one group; reflection does not define a new identification. Each nonconstant group has five members. Thus is a multiple of . The next argument explains why no smaller group can occur.
Why a nonconstant word has exactly p rotations
Lemma 3. If is prime, a nonconstant word of length has exactly distinct cyclic rotations.
Proof. If two of the rotations were equal, a shift by some , with , would leave the word unchanged. Label positions . Repeatedly shifting by visits
These positions are all distinct by Lemma 1, because . Therefore they visit every position. Invariance under the shift forces every position to carry the same symbol as position . That would make the word constant, a contradiction. Hence the rotations are distinct.
Primality is essential. The nonconstant word of length has only two distinct rotations. The shift by visits positions but not all six positions.
The combinatorial proof
Theorem 5, second proof. For every prime and integer , .
Proof. First let be a positive integer and use an alphabet with symbols. There are words of length , of which exactly are constant. Cyclic rotation splits the other words into disjoint groups. By Lemma 3, every group has words. Therefore . For , the congruence is immediate. For an arbitrary integer , choose its representative . Since , we have .
The binomial proof
Lemma 4. If is prime and , then . Here counts -element subsets of a -element set.
Proof. In the integer identity , the right side is divisible by , while is coprime to . The cancellation lemma gives the result.
Third proof of Theorem 5. In the binomial expansion, all middle coefficients vanish modulo :
Starting with , induction now gives for every nonnegative integer . As in the combinatorial proof, reducing an arbitrary integer to a nonnegative residue handles negative integers. For a concrete illustration,
Example 8. Fermat has no primality converse
Does force to be prime?
Solution. No. Take . Since ,
This composite integer passes the Fermat congruence for base . Wilson gives an equivalence; Fermat gives a necessary condition for primality, not a sufficient one. This example makes no claim about every base modulo .
5. Euler's totient function
Counting coprime integers
Definition. For , is the number of integers with and . In particular . For , the same number counts coprime representatives in .
For , the coprime representatives are , so . Also . For , neither nor is coprime to , which explains the equivalent choices of representative interval.
Prime powers
Theorem 6. If is prime and , then .
Proof. An integer fails to be coprime to exactly when it is divisible by . Among there are such multiples. Subtract them from the total.
Example 9. Counting by inclusion and exclusion
Compute .
Solution. The prime divisors of are . Among , exclude multiples of these primes. Pairwise intersections were excluded twice, so add them back; multiples of all three must then be excluded once more:
The terms count multiples of ; the final counts multiples of . Factoring the expression gives
Multiplicativity and a direct counting proof
Theorem 7. For coprime positive integers , we have .
Proof by counting. Assume first that . Send a residue modulo to its pair of remainders:
If two residues have the same pair, their difference is divisible by both and . Since these are coprime, their product divides the difference. The two residues are therefore equal modulo . There are distinct outputs and possible pairs, so every pair occurs exactly once.
An input is coprime to exactly when both coordinates are coprime to their respective moduli. There are choices for the first coordinate and for the second, proving the formula. If one modulus is , use . This proof does not assume the Chinese remainder theorem or the general totient formula.
The coprimality condition matters: , while .
The general formula
Theorem 8. If has distinct prime divisors , then . Equivalently, if , then .
Proof from prime powers. The factors are pairwise coprime. Apply Theorem 7 repeatedly, and then apply the prime-power formula from Theorem 6:
Combining with gives the equivalent factor . Each distinct prime contributes exactly one correction factor.
A second proof by counting. An integer is coprime to precisely when none of the primes divides it. For any chosen subset of these primes, the number of integers in divisible by all of them is divided by their product. Inclusion and exclusion gives
To check the signs, consider an integer divisible by exactly of these primes. Its net contribution is when , and when . Thus each coprime integer contributes exactly once.
Example 10. Using the formula
Use each distinct prime once in the product. For example, the two factors of in do not require two copies of .
6. Euler's theorem and its applications
Multiplying the coprime residues
Modulo , the coprime residues are . Multiplication by gives , the same set in a different order. We need to keep only the coprime residues: a nonzero residue such as has no inverse modulo .
Theorem 9 (Euler). For integers and with , we have .
Proof. Let be the coprime residues modulo . Each remains coprime to . The products are distinct by Lemma 1, so they rearrange exactly this set. Put . Multiplying the congruences for the rearrangement gives
Every factor of is coprime to , so is invertible. Cancel it to obtain the theorem. For prime , , and Euler reduces to Fermat.
For example, if , then . If , then also , so .
Problem 4. The last two digits
Find the last two decimal digits of .
Solution. This asks for the residue modulo . Since and , reduce . We need .
Then .
Euler supplies a guaranteed exponent . The calculation discovers a smaller one, ; the theorem does not claim that is the smallest possible exponent.
Example 11. When Euler does not apply
Can we use Euler to claim ? Find the actual remainder.
Solution. No: . Instead, compute modulo and modulo . Euler modulo gives , hence . Also . Among , the residues modulo that are , only is divisible by .
Problem 5. A stronger exponent modulo twenty-four
Prove that whenever .
Solution. The integer is odd. The two even integers are consecutive even integers, so one is divisible by and the other by . Hence . Also , so or , giving . Since and are coprime, .
This is stronger than the exponent . It also shows why the prime-modulus lemma about self-inverses cannot simply be transferred to composite moduli.
Inverses from powers
Corollary 1. If , then . For prime , this becomes .
Proof. Multiply the proposed inverse by . Euler, or Fermat in the prime case, makes the product congruent to . The exponent is allowed to be zero; for instance, modulo every invertible residue is .
For , this gives , agreeing with Example 2. The power formula is useful in proofs; Euclid often gives a shorter hand calculation.
7. Forcing many distinct prime divisors
Problem 6. Infinitely many suitable exponents
Call a positive integer rich if has more than distinct prime divisors. Is the set of rich integers finite?
Solution. It is infinite. First, for every , since and . We shall force any chosen collection of primes greater than to divide . Such a collection exists because there are infinitely many primes.
Example 12. Forcing two primes first
Take and , and put . Then . Each base is coprime to . Euler gives for each of these bases. Therefore
The same calculation works for , for every positive integer , because . This example exhibits the mechanism before the number of primes becomes large.
A fixed collection of 1001 primes
Choose distinct primes , and define
All four bases are coprime to . For every positive integer , Euler gives for . Consequently
Thus each of the distinct primes divides . The exponents are distinct positive integers, so we have an infinite family.
A second solution using only Fermat
For the same primes, let , where lcm denotes the least positive common multiple. For every , the exponent is a multiple of . Fermat gives for each of our four bases. Therefore every divides . So every positive multiple of is rich as well. The product of the would also work; using the lcm may give a smaller exponent.
For and , the Fermat choice is , compared with the Euler choice . Both force those two primes to divide the corresponding values.
The growing-product construction
Another solution lists all primes greater than in increasing order, , and takes . The same Euler argument makes divisible by all of . For , the integer is rich. To conclude infinitude, explicitly check that the exponents are distinct:
Increasing the number of forced primes is one method; fixing the primes and taking infinitely many multiples of one exponent is another. The fixed-prime method proves a slightly stronger statement about an entire arithmetic progression of exponents.
8. Review and further practice
Choosing a method
| Task | Hypothesis and method |
|---|---|
| Solve | Check . If , multiply by ; in general first require . |
| Reduce a factorial near a prime | Use Wilson: , then isolate the missing factors. |
| Reduce powers modulo a prime | If , reduce the exponent using . |
| Reduce powers modulo a composite | If , use . |
| Force many prime divisors | Choose the primes first, then a common exponent that makes each relevant power . |
Quick check 1. An inverse
Solve .
Solution. Since , we obtain .
Quick check 2. A factorial
Find .
Solution. Wilson says . Since , cancellation gives .
Quick check 3. A power
Find .
Solution. We have and . Since , Euler gives .
Problem 7. One factorial step further
For a prime , prove that .
Solution. The last three factors in Wilson's factorial give . Compare with and multiply by .
Problem 8. Totients of an odd number and its double
Prove that for every odd positive integer .
Solution. Since , multiplicativity gives . This also includes .
Problem 9. A limit to the rotation argument
Explain why counting binary words of length does not prove .
Solution. Nonconstant rotation groups need not have six members: has a group of size two, and has a group of size three. Indeed, is not divisible by . Primality was the reason all nonconstant groups had equal size in the proof of Fermat.
The common principle behind the lecture is to organize a finite set before calculating: rearrange residues, pair inverses, or group words into rotations. Before canceling or reducing an exponent, check the coprimality hypothesis.