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:

ap11(modp)a^{p-1} \equiv 1 \pmod{p}

This means that when you raise aa to the power p1p-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):

apa(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:

371=361(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: 251=241(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): 8118(mod11)8^{11} \equiv 8 \pmod{11}
Let’s check: 8118^{11} is huge, but modular arithmetic shortcuts show
8101(mod11)8^{10} \equiv 1 \pmod{11}, so multiply both sides by 8881188^{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 ap11(modp)a^{p-1} \equiv 1 \pmod{p}, then ap2a^{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,,p11, 2, 3, \dots, p-1

These are all the positive integers less than pp.


  1. Multiply each by aa:

a1, a2, a3, , a(p1)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, a1,a2,,a(p1)a \cdot 1, a \cdot 2, \dots, a \cdot (p-1) are all distinct mod pp and are just a permutation of 1,2,,p11, 2, \dots, p-1.


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

On one hand:

(a1)(a2)(a(p1))=ap1(12(p1))(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:

(a1)(a2)(a(p1))12(p1)(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 12(p1)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:

ap11(modp)a^{p-1} \equiv 1 \pmod{p}

✅ This is exactly Fermat’s Little Theorem.


Detailed explanation of step 2 above:


Step 2: Why a1,a2,,a(p1)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

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

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


Reasoning:

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

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

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

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

  3. And because 1i,jp11 \le i, j \le p-1, the difference iji - j is between (p2)-(p-2) and p2p-2, so the only way pp divides iji - j is if ij=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 a1,a2,,a(p1)a \cdot 1, a \cdot 2, \dots, a \cdot (p-1) are a permutation of 1,2,,p11, 2, \dots, p-1 in mod pp land.



Comments

Popular posts from this blog

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

Combinatorics DPP - RACE 6 - Q16 pending discussion

Algebra DPP 1.3 Quadratics