Fermat's little theorem

Let’s dive into Fermat’s Little Theorem (FLT) :


1. What it says

If pp is a prime number and aa is an integer not divisible by pp, then:

ap−1≡1(modp)a^{p-1} \equiv 1 \pmod{p}

This means that when you raise aa to the power p−1p-1 and divide by pp, the remainder is 1.


2. A slightly different but equivalent form

Sometimes it’s written as(a is any integer but p has to be prime):

ap≡a(modp)a^{p} \equiv a \pmod{p}

This form works even if aa is divisible by pp.
(You can get it by multiplying the first form by aa.)


3. Step-by-step example

Example 1:
Let p=7p = 7 (prime), a=3a = 3 (not divisible by 7).
FLT says:

37−1=36≡1(mod7)3^{7-1} = 3^6 \equiv 1 \pmod{7}

Let’s check:
36=7293^6 = 729
729÷7=104729 \div 7 = 104 remainder 1 ✅


Example 2:
p=5p = 5, a=2a = 2:
FLT: 25−1=24≡1(mod5)2^{5-1} = 2^4 \equiv 1 \pmod{5}
24=162^4 = 16, 16÷516 \div 5 remainder 1 ✅


Example 3 (alternate form):
p=11p = 11, a=8a = 8
FLT (alt form): 811≡8(mod11)8^{11} \equiv 8 \pmod{11}
Let’s check: 8118^{11} is huge, but modular arithmetic shortcuts show
810≡1(mod11)8^{10} \equiv 1 \pmod{11}, so multiply both sides by 88 ⇒ 811≡88^{11} \equiv 8 ✅


4. Why it’s useful

  • Primality testing: It’s the basis for some fast prime tests (like the Fermat primality test — although there are exceptions called Carmichael numbers).

  • Modular inverses: If ap−1≡1(modp)a^{p-1} \equiv 1 \pmod{p}, then ap−2a^{p-2} is the inverse of aa modulo pp.

  • Cryptography: Powers mod pp appear all over RSA, Diffie–Hellman, and elliptic curve cryptography.


Proof:


Here’s the elegant proof of Fermat’s Little Theorem using the “multiply all the numbers” trick.


Proof (for pp prime, aa not divisible by pp)

  1. Start with the set of numbers:

1,2,3,…,p−11, 2, 3, \dots, p-1

These are all the positive integers less than pp.


  1. Multiply each by aa:

a⋅1, a⋅2, a⋅3, …, a⋅(p−1)a \cdot 1,\ a \cdot 2,\ a \cdot 3,\ \dots,\ a \cdot (p-1)

Since pp is prime and aa is not divisible by pp, multiplying by aa just rearranges these numbers modulo pp.
That is, a⋅1,a⋅2,…,a⋅(p−1)a \cdot 1, a \cdot 2, \dots, a \cdot (p-1) are all distinct mod pp and are just a permutation of 1,2,…,p−11, 2, \dots, p-1.


  1. Take the product of all the terms (mod pp):

On one hand:

(a⋅1)⋅(a⋅2)⋅⋯⋅(a⋅(p−1))=ap−1⋅(1⋅2⋅⋯⋅(p−1))(a \cdot 1) \cdot (a \cdot 2) \cdot \dots \cdot (a \cdot (p-1)) = a^{p-1} \cdot (1 \cdot 2 \cdot \dots \cdot (p-1))

On the other hand, since it’s just a rearrangement:

(a⋅1)⋅(a⋅2)⋅⋯⋅(a⋅(p−1))≡1⋅2⋅⋯⋅(p−1)(modp)(a \cdot 1) \cdot (a \cdot 2) \cdot \dots \cdot (a \cdot (p-1)) \equiv 1 \cdot 2 \cdot \dots \cdot (p-1) \pmod{p}


  1. Cancel the factorial part:
    The product 1⋅2⋅⋯⋅(p−1)1 \cdot 2 \cdot \dots \cdot (p-1) is not divisible by pp, so it has a multiplicative inverse modulo pp.
    Cancelling it from both sides gives:

ap−1≡1(modp)a^{p-1} \equiv 1 \pmod{p}

✅ This is exactly Fermat’s Little Theorem.


Detailed explanation of step 2 above:


Step 2: Why a⋅1,a⋅2,…,a⋅(p−1)a \cdot 1, a \cdot 2, \dots, a \cdot (p-1) are all distinct mod pp

We’re working modulo pp, where pp is prime and aa is not divisible by pp.
We want to show that if

a⋅i≡a⋅j(modp)a \cdot i \equiv a \cdot j \pmod{p}

then i≡j(modp)i \equiv j \pmod{p}.


Reasoning:

  1. a⋅i≡a⋅j(modp)a \cdot i \equiv a \cdot j \pmod{p} means:

p divides a(i−j)p \ \text{divides} \ a(i - j)

  1. Since pp is prime, if pp divides the product a(i−j)a(i - j), then pp must divide either aa or i−ji - j.

  2. But aa is not divisible by pp (that’s an assumption of the theorem),
    so the only option is that pp divides i−ji - j.

  3. And because 1≤i,j≤p−11 \le i, j \le p-1, the difference i−ji - j is between −(p−2)-(p-2) and p−2p-2, so the only way pp divides i−ji - j is if i−j=0i - j = 0, i.e.:

i=ji = j


Conclusion:
Multiplying by aa modulo pp doesn’t make any two numbers “collapse” into the same remainder — it just reorders them.

That’s why a⋅1,a⋅2,…,a⋅(p−1)a \cdot 1, a \cdot 2, \dots, a \cdot (p-1) are a permutation of 1,2,…,p−11, 2, \dots, p-1 in mod pp land.



Comments

Popular posts from this blog

Simon's factoring trick(complete the rectangle)

IOQM 2023 solutions

IOQM 2024 Paper solutions (Done 1-21, 29)