Fermatβs Little Theorem
Section titled βFermatβs Little TheoremβRemainder cycles become more predictable when the base is coprime to the modulus. For a prime and an integer not divisible by , Fermatβs little theorem states
Multiplication by permutes the nonzero residues modulo . Multiplying all those residues gives ; the factorial is invertible modulo , so it cancels.
The equivalent statement holds for every integer , including multiples of .
Example. Find the remainder when is divided by .
Since and ,
Do not replace by for an arbitrary composite modulus. A different exponent is needed.
Eulerβs Totient Function and Theorem
Section titled βEulerβs Totient Function and TheoremβThe totient counts integers in coprime to . If the distinct prime divisors of are , inclusionβexclusion gives
For , the same residue-permutation proof gives Eulerβs theorem:
Example. Find the last two decimal digits of .
Since , we have . Eulerβs theorem permits reduction of the exponent modulo forty. In this case a shorter cycle is visible: . Therefore
The last two digits are .
If the base shares a factor with the modulus, exponent reduction can fail. For example, , but while . Always check coprimality before using Eulerβs theorem.
Multiplicative Order
Section titled βMultiplicative OrderβFor , the order is the smallest positive integer with . Every exponent giving one is a multiple of .
To prove the last statement, divide an exponent by : with . If , then , so minimality forces . In particular,
Example. Find all positive integers for which .
The first three powers of two modulo seven are , so . Hence exactly when . The solutions are all positive multiples of three.
To find an order, test divisors of rather than every exponent. For a prime modulus , a number with order is called a primitive root. For instance, two has order ten modulo eleven because , , and ; these exclude all proper divisors of ten.
Restricting Prime Divisors
Section titled βRestricting Prime DivisorsβIf a prime divides an expression like , the order of modulo links the exponent to . For , use while keeping .
Example. Let an odd prime divide . Prove .
We have and . The order divides but does not divide . Every proper divisor of divides , so the order is exactly . Fermatβs theorem gives .
The power-of-two exponent makes the order exact. For a general , the order need not equal , so prove it rather than assuming it.
Wilsonβs Theorem
Section titled βWilsonβs TheoremβFor a prime ,
For odd , pair each nonzero residue with its multiplicative inverse. Only and are their own inverses, because implies modulo a prime. All other pairs multiply to one, leaving product . The prime can be checked directly.
Example. Find the remainder of modulo .
Wilson gives . Since ,
Finding an Order Efficiently
Section titled βFinding an Order EfficientlyβOnce Euler or Fermat supplies an exponent with , the actual order divides . Factor and repeatedly test whether the exponent can be divided by one of its prime factors.
If , replace by and continue. If the test fails, the order requires that remaining prime-power contribution. This is faster than checking all exponents and makes the minimality argument explicit.
Example. Show that three has order sixteen modulo seventeen.
Fermat gives an order dividing sixteen. Compute
The order does not divide eight. Every proper divisor of sixteen does divide eight, so the order must be sixteen.
When the candidate exponent has several prime factors, failing only one reduced-exponent test may not establish the full order. To prove order twelve, for example, check that the twelfth power is one while the sixth and fourth powers are not. Every proper divisor of twelve divides at least one of six or four.
Combining Orders by CRT
Section titled βCombining Orders by CRTβFor coprime moduli and a base coprime to both,
An exponent produces one modulo the product exactly when it produces one modulo both factors. The two order divisibility requirements are therefore equivalent to being a multiple of their least common multiple.
Example. Find the smallest positive for which .
Factor . The order of two modulo seven is three. Modulo nine, and , so the order is six.
Their least common multiple is six, and confirms the answer.
This method also handles a simultaneous system of exponential divisibility conditions. First identify the order required by each modulus; only then combine the exponent conditions. Adding the orders or multiplying them indiscriminately can give a nonminimal answer.
Nested Exponents
Section titled βNested ExponentsβFor a power tower, reduce the outer exponent modulo the order of the outer base. The relevant modulus for the exponent is an order, not necessarily the original numerical modulus.
Example. Find the last two digits of .
Modulo one hundred, the order of seven is four: while . Thus only is needed.
Since and seven is odd, . Therefore
The final two digits are 43. Reducing the exponent modulo one hundred would not be the principle that justifies this calculation.
For a noncoprime base, a tower requires separate prime-power analysis. One part of the modulus may force a sufficiently high power to vanish, while another part cycles. Check this before building an exponent-reduction chain.
Orders Modulo Prime Powers
Section titled βOrders Modulo Prime PowersβAn order modulo does not automatically stay the same modulo . Let be odd, , and . Write . For ,
To derive the formula, any successful exponent is because reduction modulo already forces that multiple. LTE gives
Divisibility by therefore requires exactly the extra power in . This links order, divisibility, and valuation in one calculation.
Example. Find the orders of two modulo forty-nine and three hundred forty-three.
Modulo seven, two has order three, and has valuation one. The formula gives
The prime-power formula used the odd-prime LTE hypotheses. Powers of two have different lifting behavior and must be handled separately.
Primitive Roots and Exponential Equations
Section titled βPrimitive Roots and Exponential EquationsβA primitive root modulo an odd prime generates every nonzero residue by its powers. If has order , the equality is equivalent to .
Thus an equation between powers of the same primitive root becomes a linear congruence in the exponents. If the base has smaller order, use that smaller order instead.
Example. Find all positive integers satisfying .
We proved three has order sixteen. Since , the condition is
The inverse of three modulo sixteen is eleven, giving . All positive integers in this class work, and order sixteen proves no other classes do.
An odd prime admits primitive roots, but finding a convenient one is a separate task. For many contest problems, determining the order of the specific given base is enough; constructing a generator for the whole residue group would add unnecessary work.
Why Fermatβs Converse Fails
Section titled βWhy Fermatβs Converse FailsβIf is prime, every base coprime to it satisfies . The converse is false. Some composite numbers satisfy the same congruence for every coprime base; these are Carmichael numbers.
For example, . If is coprime to 561, Fermat applied to the three prime factors gives exponents two, ten, and sixteen. Each divides 560, so modulo each factor, and CRT gives
Thus passing a Fermat congruence does not establish primality. The argument does not require testing hundreds of bases; the prime-factor structure explains every coprime base at once.
Wilsonβs theorem has a genuine converse for integers greater than one, but computing the factorial may be impractical. Distinguish a theoremβs logical strength from the efficiency of using it in a numerical problem.
Decimal Periods and a Wilson Construction
Section titled βDecimal Periods and a Wilson ConstructionβIf , the repeating decimal period of is . Long division returns to its initial remainder precisely when . For denominator seven, the order is six, explaining the six-digit repeating block.
When the denominator contains powers of two or five, those factors produce an initial nonrepeating portion. The period afterward is controlled by the remaining factor coprime to ten.
Wilson also constructs a square root of negative one modulo a prime . Set and pair the factorial terms:
Here is even, so Wilson gives . For , and . This provides an explicit root and connects factorial identities with quadratic residues.
Fermat Numbers and New Prime Factors
Section titled βFermat Numbers and New Prime FactorsβDefine . Repeated difference-of-squares factorization gives
One proof is induction: multiplying by produces , the next required product.
Any common divisor of and an earlier therefore divides two. All Fermat numbers are odd, so they are pairwise coprime. Choosing a prime divisor from each gives infinitely many distinct primes.
If an odd prime divides , then . Its order is exactly , since every proper divisor of that power of two divides . Therefore .
The numbers themselves need not be prime. For example, 641 divides . To verify this without long division, use
The first identity gives modulo 641, while the second gives . Hence , proving the divisibility.
Pairwise coprimality guarantees new prime factors, not primality of every term. That distinction is the point of the construction.
Counting Roots through a Primitive Root
Section titled βCounting Roots through a Primitive RootβIf is primitive modulo an odd prime , every nonzero residue is uniquely with taken modulo . Thus becomes and has exactly solutions.
Example. Find every solution of .
There are exactly four solutions because . Using primitive root three, the allowed exponents are , giving
The factorization provides a second route: the roots of one are positive and negative one, and the roots of negative one are four and thirteen.
The count follows from a linear congruence in exponents, while the polynomial degree confirms there cannot be more than four roots over the prime field.
Wilsonβs Converse
Section titled βWilsonβs ConverseβFor an integer , if , then is prime. If it were composite, it would have a divisor with . That divisor occurs in the factorial, so reducing the congruence modulo would say zero is negative one, a contradiction.
Thus Wilson provides an if-and-only-if primality criterion, unlike Fermat. Its drawback is computational rather than logical: a factorial near a large candidate can be costly to evaluate. In contest problems, Wilson is most effective when almost all factors cancel or pair with inverses.
The Order of a Power
Section titled βThe Order of a PowerβIf has order modulo , then
for positive . Indeed, equals one precisely when , whose least positive solution is the displayed quotient.
For example, three has order sixteen modulo seventeen. Its square nine has order eight, while its cube twenty-seven still has order sixteen because three is coprime to sixteen.
This rule is useful when several bases in a problem are powers of one known element. It avoids recalculating a full remainder cycle for each base and explains exactly when taking a power shortens that cycle.