Fermat's Little Theorem, also known as Fermat's remainder theorem, is a fundamental result in number theory that deals with properties of prime numbers and modular arithmetic.
Fermat’s Little Theorem states that
"if p is a prime number and a is an integer such that a is not divisible by p, then
a^{p-1} \equiv 1 \pmod{p} ."
This means that when ap−1 is divided by p, the remainder is 1.
This also can be written as ap ≡ a (mod p).
For Example,
Let's take p = 7 (a prime number), and a = 3. According to the Fermat's Little Theorem :
3^{7-1} = 3^6 \equiv 1 \pmod{7} This means when you calculate 36 and divide it by 7, the remainder is 1.
Proof of Fermat's Little Theorem
Using Euler’s Theorem (Simplified Approach)
Fermat’s Little Theorem is a special case of Euler’s Theorem, which states:
If a is coprime to n, then:
a^{\phi(n)} \equiv 1 \ (\text{mod} \ n)
Where
For a prime number p,
a^{p-1} \equiv 1 \ (\text{mod} \ p)
This completes the proof of Fermat’s Little Theorem in a concise and clear manner, without needing Wilson’s Theorem.
Using Wilson’s Theorem (Advanced)
If you want to explore a more involved proof, it goes like this:
Let:
Modulo p, this set contains p−1 distinct values (none repeat), because if:
So:
By Wilson’s Theorem:
(p - 1)! \equiv -1 \ (\text{mod} \ p)
So:
Divide both sides by (p - 1)! (valid since it’s not divisible by p):
a^{p-1} \equiv 1 \ (\text{mod} \ p)
Applications in Computer Science
Cryptography
- For RSA Decryption, to compute m = cd (mod n) via Chinese Remainder Theorem
- In Diffie Hellmann Key Exchange Algorithm for secure key exchange by optimizing calculations of large powers modulo a prime.
- In Digital signature, ensures that inverse exists.
Primality Testing
- For an n to be prime, checking if an-1 = 1 (mod n). Exceptions for Carmichael numbers like 561, which is not a prime but still passes the test. This is the basis for Monte Carlo primality tests.
Algorithmic Optimizations
- For modular inverse computation, for prime p, a-1 ≡ ap-2 (mod p) and for exponent reduction; FLT allows reducing exponents, speeding up computations.
Hash Functions
- FLT ensures uniform distribution in hash functions using prime-sized tables (e.g., universal hashing).
➣Practice: Solved Examples