Omni Calculator logo

Fermat's little theorem calculator will teach you all there is about this famous result in elementary number theory. Read on to find out:

  • What Fermat's little theorem is about and why it's called "little";
  • How to perform primality test using this theorem;
  • How to use Fermat's little theorem to find the multiplicative inverse modulo; and
  • When was Fermat's little theorem proved — and was it Fermat's achievement?

We'll also see examples of Fermat's little theorem applied to concrete numbers. Enjoy!

💡 We assume you already know what the math operation modulo n is. If this is not the case or you feel you need a refresher, go and check out our modulo calculator!

What is Fermat's little theorem?

Fermat's little theorem is one of the fundamental results of number theory. It says that if p is a prime number and a is an integer, then ap – a is divisible by p. In modulo notation:

ap ≡ a (mod p)

In particular, if a is not divisible by p, then:

ap-1 ≡ 1 (mod p)

🙋 The condition that a is not divisible by p can be equivalently stated as a and p being coprime (or relatively prime) numbers. The quickest way to verify this requirement is to compute their GCF. See our relatively prime calculator to learn more.

Once we know what Fermat's little theorem is, let's see how it works in practice. We'll go together through some examples of Fermat's little theorem applied to concrete numbers.

Example 1

Let's consider p = 7 and a = 15. a is not divisible by p, so the theorem says that

157-1 = 156 ≡ 1 (mod 7)

Indeed, we have

156 – 1 = 11390624 = 7 × 1627232

Example 2

Be careful to check the assumptions! If p = 7 and a = 14, then 146 is not equal to 1 modulo 7:

146 – 1 ≡ 6 (mod 7)

This is because 14 and 7 are not coprime — 14 is divisible by 7. So, we should use the version of Fermat's little theorem for non-coprime numbers — the one that states ap ≡ a (mod p):

147 ≡ 14 (mod 7)


147 – 14 = 7 × 15059070

🔎 Why is Fermat's little theorem called "little"? It's to distinguish it from Fermat's "great" or "last" theorem, which says that if n is an integer greater than 2, then no three positive integers x, y, and z satisfy the equation xn + yn = zn. This theorem was stated by Fermat in the 17th century but proved only in 1995 by Andrew Wiles.

How to use this Fermat's little theorem calculator

Omni's calculator for Fermat's little theorem is really simple to use:

  1. Our tool accepts two inputs: the integers a and p.

  2. Remember that p must be a prime number. You can use Omni's prime number calculator to verify if the number you want to enter is prime. If it is not, our Fermat's little theorem calculator will display a warning and refuse to cooperate further.

  3. Our calculator will also check if your numbers are coprime to decide which version of Fermat's last theorem is appropriate.

  4. In either case, the statement of Fermat's little theorem applied to your input will appear.

How do I find multiplicative inverse using Fermat's little theorem?

To find the multiplicative inverse of a modulo p using Fermat's little theorem:

  1. Write the claim of Fermat's little theorem as ap-1 ≡ 1 (mod p).
  2. Recall the assumptions: p must be prime and a must not be a multiple of p.
  3. Verify that your numbers satisfy these assumptions.
  4. Rewrite the claim a × ap-2 ≡ 1 (mod p).
  5. That is, the multiplicative inverse of a modulo p is equal to ap-2.

How do I use Fermat's little theorem to test primality?

To check if p is a prime number using Fermat's little theorem:

  1. Pick a random integer a ∈ {2, ... p-2} not divisible by p.
  2. Compute ap-1 (mod p).
  3. If the result is not 1, then p is definitely not prime.
  4. If the result is equal to 1, then we choose a different a and repeat the procedure from Step 2.
  5. If the test cannot decide after many repetitions, then p is probably prime.


What is 19^11 mod 11 by Fermat's little theorem?

The answer is 8. This is because Fermat’s little theorem tells us that 1911 ≡ 19 (mod 11). We can further calculate that 19 = 1 × 11 + 8, which means that 19 (mod 11) ≡ 8, as claimed.

When using Fermat’s little theorem, always remember to verify the assumptions! We could use this theorem here since 11 is a prime number.

When was Fermat's little theorem proved?

Fermat formulated his "little" theorem in October 1640 in a letter to his friend Frénicle de Bessy. However, he did not provide a proof, saying that he would gladly have attached it "if I did not fear its being too long". The first proof was published by Euler in 1736, but it turned out that Leibniz had found the same proof sometime before 1683 but kept it in an unpublished manuscript.

Anna Szczepanek, PhD
Related calculators
Fermat's little theorem
If a is an integer and p is a prime number:
ap ≡ a (mod p)
If additionally a and p are coprime:
ap-1 ≡ 1 (mod p)
Input your numbers...
Check out 75 similar arithmetic calculators ➗
Absolute changeAbsolute valueAdding and subtracting fractions… 72 more
People also viewed…

Flat vs. round Earth

Omni's not-flat Earth calculator helps you perform three experiments that prove the world is round.

Humans vs vampires

Vampire apocalypse calculator shows what would happen if vampires were among us using the predator - prey model.

Isosceles triangle find A

This isosceles triangle find A calculator is designed to help you find the missing side and angles of a triangle given two values.

Trapezoid side

Find the length of the missing side (a, b, c or d) of a trapezoid with the trapezoid side calculator.
Copyright by Omni Calculator sp. z o.o.
Privacy, Cookies & Terms of Service