The Daily Reckoning
Why Does a Prime Make Giant Powers Loop?
Fermat’s little theorem turns multiplication modulo a prime into a collision-free rearrangement—and reduces 2¹⁰⁰⁰ to one small remainder.
Arithmetic Behind Secure Messages · Part 2 of 3
- Difficulty
- Intermediate
- Area
- Numbers and algebra
- Reading time
- 9 minutes
- Prerequisites
- Modular arithmetic and congruence · Prime numbers · Products and exponents
The number has 302 decimal digits. What remainder does that number leave after division by ?
One route is to calculate all 302 digits and divide. A theorem about prime numbers reaches the answer using instead. The theorem works because multiplication by a nonzero remainder modulo a prime cannot make two different remainders collide.
This lesson continues yesterday’s introduction to modular arithmetic. Congruence notation such as says that and leave the same remainder after division by .
Six passengers, six seats
Start with the six nonzero remainders modulo :
Multiply each remainder by , then keep only the remainder after division by :
Every number from through appears once in the second list. Multiplication by changed the seating order without losing a passenger or putting two passengers in one seat.
The diagram below draws every assignment from the first list to the second. Change the prime modulus or the multiplier. The lines cross in different places, but each output circle still receives exactly one arrow.
Interactive residue map
Multiply every nonzero remainder by the same number
×3 sends 1, 2, 3, 4, 5, 6 to 3, 6, 2, 5, 1, 4 modulo 7.
- Repeated outputs
- 0
- Landings on zero
- 0
- Power consequence
- 3⁶ ≡ 1 (mod 7)
- 1 → 3
- 2 → 6
- 3 → 2
- 4 → 5
- 5 → 1
- 6 → 4
Why are collisions impossible? Suppose two source remainders and land together after multiplication by . In symbols,
The congruence says that divides . Because is prime and does not divide , Euclid’s lemma says that must divide . Both and lie between and , so the only possible multiple of for is . Therefore : the allegedly different sources were the same source.
No source can land on , either. If , then divides . The prime divides neither nor any from through , so that landing is impossible.
We now have six distinct outputs, and all six are chosen from the six nonzero remainders. The outputs must therefore be a rearrangement of .
The loop guaranteed by a prime
The same reasoning works for every prime modulus. Fermat’s little theorem states:
Let be a prime number, and let be an integer that does not divide. Then
The exponent counts the nonzero remainders modulo . To prove the theorem, multiply those remainders by :
The collision argument used for and shows that these products, after reduction modulo , are a rearrangement of
Rearranging factors does not change their product, so
The symbol means . None of those factors is divisible by , so their product has a multiplicative inverse modulo . Multiplying both sides by that inverse legally cancels and leaves
For and , the proof says . Six more factors of will always return a power to the same remainder. The shortest cycle may be smaller than , but is a guaranteed return time.
Worked example: modulo
The modulus is prime, and does not divide . Fermat’s little theorem gives
Next, divide the exponent by :
Rewrite the power using that quotient and remainder:
Therefore the 302-digit number leaves remainder 3 after division by .
Try the prime shortcut
Problem 1
Find the remainder when is divided by .
Reveal the solution
The number is prime, and does not divide , so
Reduce the exponent:
Therefore
Compute the sixth power in small steps:
The remainder is 5.
Problem 2
Find a multiplicative inverse of modulo . In other words, find a number for which .
Reveal the solution
Fermat’s little theorem gives
Write as :
Therefore is an inverse of . Reduce it modulo :
so . A direct check confirms the result:
One multiplicative inverse is 5.
A theorem passed by letter, then proved by an academy mathematician
Pierre de Fermat stated the result in an October 1640 letter to Bernard Frénicle de Bessy, one of the few correspondents who shared Fermat’s interest in number theory. Fermat did not include a proof. The omission fit his usual mathematical practice: Fermat posed results and challenges in private correspondence far more readily than he prepared finished publications.
That habit was tied to Fermat’s working life. He was a lawyer and government official who purchased an office as a councillor in the Parlement of Toulouse by 1631. His mathematical network ran through letters among figures such as Pierre de Carcavi and Marin Mersenne. A civil war known as the Fronde, official duties, and a plague that nearly killed Fermat later interrupted those exchanges. The theorem emerged from an elite European correspondence network rather than from a university post or a mathematical journal.
Leonhard Euler wrote the first published proof in 1736. The St Petersburg Academy’s proceedings printed it in 1741 under the title A Proof of Certain Theorems Regarding Prime Numbers. The Euler Archive’s record of the paper identifies it as the first proof and dates both composition and publication.
Euler’s institutional position differed from Fermat’s. Euler joined the St Petersburg Academy of Sciences in 1727, became a full academy member in 1730, and took its senior mathematics chair in 1733. The academy supplied salary, colleagues, publication machinery, and state projects ranging from cartography to shipbuilding. Fermat’s correspondence allowed the claim to travel; the academy system gave Euler’s proof a durable printed home.
The rearrangement proof in this lesson is not Euler’s 1736 argument. Euler’s paper instead advances through successive bases and mathematical induction.
Where the prime loop is used
Modular division. Ordinary division is not available for every remainder system. Fermat’s little theorem constructs inverses modulo a prime: is an inverse of because . Computer algebra, coding theory, and cryptographic algorithms use these inverses to solve modular equations.
Primality screening. If a candidate integer and a test base satisfy , then is certainly composite. Passing the test does not prove that is prime; some composite numbers imitate prime behavior for one base, and Carmichael numbers do so for every base coprime to them. Current standards therefore use stronger checks. The U.S. National Institute of Standards and Technology’s Digital Signature Standard, FIPS 186-5, specifies Miller–Rabin and Lucas probable-prime tests when generating primes for certain digital-signature and Rivest–Shamir–Adleman (RSA) keys.
Public-key cryptography. The prime-number case developed here is one ingredient in the arithmetic behind RSA. The Internet Engineering Task Force’s RSA specification defines encryption and decryption primitives using modular powers. Fermat’s theorem alone does not explain why the private exponent reverses the public exponent when the modulus is a product of primes. Part three will supply Euler’s broader theorem and work through that reversal with small numbers.
One idea to remember
Multiplication by a nonzero remainder modulo a prime can only rearrange the nonzero remainders. Multiplying the whole rearrangement together forces , which turns enormous exponents into manageable ones.
Continue with modular arithmetic and repeating residue cycles, or return to why multiplying by makes a quarter-turn for another example of multiplication acting as a transformation. Part three of Arithmetic Behind Secure Messages will replace the prime modulus with the composite modulus used by RSA.
Sources
- Pierre de Fermat, Œuvres de Fermat, volume 2: Correspondance, edited by Paul Tannery and Charles Henry, 1894, containing Fermat’s 1640 correspondence with Bernard Frénicle de Bessy.
- University of St Andrews MacTutor, “Pierre de Fermat”, for Fermat’s legal career, correspondence network, interruptions during the Fronde and plague, and publication habits.
- Leonhard Euler, Theorematum quorundam ad numeros primos spectantium demonstratio (A Proof of Certain Theorems Regarding Prime Numbers), written 1736 and published in the St Petersburg Academy proceedings in 1741; catalogued by the Euler Archive at the University of the Pacific.
- University of St Andrews MacTutor, “Leonhard Euler”, for Euler’s appointments and working conditions at the St Petersburg Academy of Sciences.
- National Institute of Standards and Technology, FIPS 186-5: Digital Signature Standard, February 2023, especially Appendices B.3 and C on probable-prime generation and testing.
- Kathleen Moriarty et al., RFC 8017: PKCS #1: RSA Cryptography Specifications Version 2.2, Internet Engineering Task Force, November 2016.