Fermat's Little Theorem Calculator
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 a^{p} – a is divisible by p. In modulo notation:
a^{p} ≡ a (mod p)
In particular, if a is not divisible by p, then:
a^{p1} ≡ 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
15^{71} = 15^{6} ≡ 1 (mod 7)
Indeed, we have
15^{6} – 1 = 11390624 = 7 × 1627232
Example 2
Be careful to check the assumptions! If p = 7 and a = 14, then 14^{6} is not equal to 1 modulo 7:
14^{6} – 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 noncoprime numbers — the one that states a^{p} ≡ a (mod p):
14^{7} ≡ 14 (mod 7)
Indeed:
14^{7} – 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 x^{n} + y^{n} = z^{n}. 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:

Our tool accepts two inputs: the integers
a
andp
. 
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. 
Our calculator will also check if your numbers are coprime to decide which version of Fermat's last theorem is appropriate.

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:
 Write the claim of Fermat's little theorem as a^{p1} ≡ 1 (mod p).
 Recall the assumptions: p must be prime and a must not be a multiple of p.
 Verify that your numbers satisfy these assumptions.
 Rewrite the claim a × a^{p2} ≡ 1 (mod p).
 That is, the multiplicative inverse of a modulo p is equal to a^{p2}.
How do I use Fermat's little theorem to test primality?
To check if p is a prime number using Fermat's little theorem:
 Pick a random integer a ∈ {2, ... p2} not divisible by p.
 Compute a^{p1} (mod p).
 If the result is not 1, then p is definitely not prime.
 If the result is equal to 1, then we choose a different a and repeat the procedure from Step 2.
 If the test cannot decide after many repetitions, then p is probably prime.
FAQ
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 19^{11} ≡ 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.