taocp

This site has no text of the book. Keep your own copy of TAOCP next to it. See what is checked.

Exercise · Volume 1 · 1.2.4-25

Exercise 1.2.4-25

proved in Lean solution written

RatingM02
MarkersM (mathematical)
KindK1, prove: show that a stated fact is true from the written solution
SectionSection 1.2.4 of Volume 1. Companion chapter: Integer functions and elementary number theory

The task

Use Fermat's theorem to show that, for a prime pp, the remainder ap−1 mod pa^{p-1} \bmod p is 11 when p∤ap \nmid a and 00 when p∣ap \mid a.

The exact wording is in your copy of the book.

Hints

Open one hint at a time. Try the exercise again after each.

Hint 1

Treat p∣ap \mid a and p∤ap \nmid a separately. In the second case cancel a factor aa with Law B.

Solution

Show the solution

If p∣ap \mid a, then pp divides ap−1a^{p-1} since p−1≥1p - 1 \ge 1. So ap−1 mod p=0a^{p-1} \bmod p = 0.

If p∤ap \nmid a, then a⊥pa \perp p, because gcd⁡(a,p)\gcd(a, p) divides the prime pp and is not pp. Theorem F says ap≡aa^p \equiv a, that is a⋅ap−1≡a⋅1(modp)a \cdot a^{p-1} \equiv a \cdot 1 \pmod p. Law B with the factor aa gives ap−1≡1(modp)a^{p-1} \equiv 1 \pmod p. Since 0≤1<p0 \le 1 < p, the remainder is 11 (Exercise 1.2.4-16).

Both cases together say ap−1 mod p=[p∤a]a^{p-1} \bmod p = [p \nmid a]. □\square

Check

For p=7p = 7 and a=1,…,6a = 1, \ldots, 6 a run gives a6 mod 7=1a^6 \bmod 7 = 1 each time, and for a=7a = 7 and a=14a = 14 it gives 00. For p=2p = 2 and a=3a = 3: 3 mod 2=13 \bmod 2 = 1.

Remarks

The form ap−1≡1a^{p-1} \equiv 1 is the one used in primality tests. A composite nn that passes it for all a⊥na \perp n is a Carmichael number, such as 561561.

This solution is checked, and a person has not reviewed it yet. The source.

In Lean

proved The statement and its proof are in Lean. The kernel accepts the proof, and it uses the standard axioms only.

The status is computed from the Lean build. The node of the map.

Something is wrong? Report it.