Fermat’s Little Theorem - Statement, Proof with Example

Last Updated : 13 May, 2026

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 \phi(n) is Euler’s totient function (count of numbers less than n and coprime to it).

For a prime number p, \phi(p) = p - 1. So:

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: S = \{a, 2a, 3a, \ldots, (p - 1)a\}

Modulo p, this set contains p−1 distinct values (none repeat), because if:

ia \equiv ja \ (\text{mod} \ p) \Rightarrow (i - j)a \equiv 0 \Rightarrow i = j \ (\text{since } a \not\equiv 0 \ \text{and } p \ \text{is prime})

So: a \cdot 2a \cdot \ldots \cdot (p - 1)a = a^{p-1} \cdot (p - 1)!

By Wilson’s Theorem: (p - 1)! \equiv -1 \ (\text{mod} \ p)

So: a^{p-1} \cdot (p - 1)! \equiv (p - 1)! \ (\text{mod} \ p)

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).

Solved Examples

Example 1: Find the remainder when 7100 is divided by 13.

Solution:

Since 13 is a prime number, we can apply Fermat's Little Theorem, which states:

7^{12} \equiv 1 \ (\text{mod} \ 13)

Now, 100= 12 ×8 +4 , so:

7^{100} = (7^{12})^8 \cdot 7^4 \equiv 1^8 \cdot 7^4 \equiv 7^4 \ (\text{mod} \ 13)

Calculate 7^4 \mod 13:

  • 7^2 = 49 \Rightarrow 49 \mod 13 = 10
  • 7^4 = (7^2)^2 = 10^2 = 100 \Rightarrow 100 \mod 13 = 9

Result: Remainder when 7^{100} is divided by 13 is 9.

Example 2: Find the remainder of 3100,000 when divided by 53.

Solution:

Since 53 is a prime number, we can apply Fermat's Little Theorem.

3^{52} \equiv 1 \ (\text{mod} \ 53)

Now:

100000 = 52 \times 1923 + 4 \Rightarrow 3^{100000} = (3^{52})^{1923} \cdot 3^4 \equiv 1^{1923} \cdot 3^4 = 3^4 \ (\text{mod} \ 53)

  • 3^4 = 81 \Rightarrow 81 \mod 53 = 28

Result: Remainder when 3^{100000} is divided by 53 is 28.

Practice Questions

1. Find the remainder when 5123 is divided by 13.

2. Compute the remainder when 1150 is divided by 17.

3. What is the remainder when 7300 is divided by 19?

4. Calculate the remainder of 2200 modulo 31.

5. Find the remainder when 875 is divided by 29.

6. Determine the remainder when 9100 is divided by 23.

7. What is the remainder when 42024 is divided by 7?

8. Compute the remainder of 699 modulo 37.

9. Find the remainder when 10500 is divided by 43.

10. What is the remainder when 364 is divided by 41?

Answer Keys

  1. 8
  2. 2
  3. 1
  4. 1
  5. 2
  6. 9
  7. 2
  8. 31
  9. 9
  10. 1
Comment