Fermat's Little Theorem
If is prime and , then ; equivalently for every . So exponents can be reduced mod : when .
The exponent is the number of nonzero residues mod , and the theorem says multiplying by permutes them: are the same residues in a different order, so their products agree, , and cancels. This is a group-theory fact in disguise (Lagrange's theorem), and Euler's theorem is the same argument with the coprime residues mod .
Find . Since , Fermat gives , so whole blocks of in the exponent contribute nothing: and . Answer .
Show that is divisible by for every integer . The three primes are coprime, so treat them one at a time. Mod : Fermat in the form holds for every . Mod : , so . Mod : , so every power of is . Hence , and all divide .
Is prime? If it were, Fermat would force . Compute: , so . Since , is composite — proved without finding a factor. For large numbers this "Fermat test" is how computers screen for primes, since fast exponentiation is cheap and factoring is not.
Reducing the exponent mod instead of mod . For , ", so " is wrong; the cycle has length , , and . And the theorem needs : , not .
Find .
Show the answerHide the answer
By Fermat . Since , .
Euler's Theorem and
counts the integers in coprime to . For : . Euler: if then .
The product formula is a sieve: of the numbers , a fraction are multiples of , and removing them leaves the fraction ; among what remains, the multiples of are again a fraction , because and are independent (a fact made precise by the Chinese remainder theorem). Euler's theorem generalizes Fermat — for prime , — and lets you reduce exponents mod for any modulus, as long as the base is coprime to it.
, so . Laid out in rows of , the coprime numbers are exactly those or : half the columns are even, and of the odd columns one is a multiple of . Two columns of six rows: .
Find . and , so . Here the order is even shorter: , . So . The last two digits are .
Find the last digit of . Mod , , so the exponent matters only mod . And , so . Hence : the last digit is . Towers are handled from the top down, each level mod the totient of the level below.
Using Euler when — , not . Split the modulus into prime powers and treat the non-coprime part directly (the CRT topic shows how).
Compute , then find .
Show the answerHide the answer
: . Since , Euler gives .
Wilson's Theorem
Wilson: for a prime , . For composite , (and ). So Wilson's congruence holds exactly for the primes.
Each of has an inverse mod , and the numbers pair off with their inverses, each pair multiplying to . The only numbers equal to their own inverse solve , i.e. , so . The product of everything is therefore . For composite , some factor of appears among and the product shares that factor with .
Pair each of with its inverse mod : , , , , and each of these is . What is left is . So , as a direct check confirms: .
Wilson gives . And with , so and . Peeling factors off the top of like this turns Wilson into a tool for nearby factorials.
is prime, so . Peel off three factors: , so , i.e. . Thus , and gives . So .
Using Wilson with a composite modulus. , not : the factors and of both appear in . The pairing argument breaks because and have no inverses mod .
Find .
Show the answerHide the answer
Wilson: . Since , . So , and .
Why It Works
Let . The residues are pairwise distinct mod : if then , and since , , forcing (both lie in ). None is . So they are the residues in some order, and multiplying them together gives . Since (all its factors are smaller than ), cancel it: . Replace "" by "the residues coprime to " and the identical argument proves Euler's theorem.
For and check directly: and . For larger , every in has a unique inverse in , and the inverse is neither nor (those are their own inverses) nor itself (that would need , so ). So split into pairs with product , and . Conversely, if is composite with , , then and (or and when ) appear separately in , so .