Fermat’s Little Theorem Calculator

Quick answer

The Fermat's little theorem calculator checks the theorem for a whole number a and a prime p, showing aᵖ mod p and a^(p−1) mod p with exact modular arithmetic.

Theorem applied
a and p are coprime, so a^(p−1) ≡ 1 (mod p)
aᵖ mod p
3⁷ ≡ 3 ≡ 3 (mod 7)
a^(p−1) mod p
3⁶ ≡ 1 (mod 7)

Fermat’s little theorem is a foundation of number theory and cryptography. It powers primality tests (if a^(n−1) mod n ≠ 1, n is definitely composite) and explains why RSA decryption works.

How to use the Fermat’s Little Theorem Calculator

  1. a
  2. p (prime)

Everything is calculated in your browser, so results appear instantly and nothing you type is sent to a server.

How it works

The calculator first checks that p is prime, then computes the powers with fast modular exponentiation, so even large exponents are handled exactly.

Formula

p prime: aᵖ ≡ a (mod p); if p ∤ a: a^(p−1) ≡ 1 (mod p)

Worked example

Inputs: a: 3; p (prime): 7.
Results: Theorem applied = a and p are coprime, so a^(p−1) ≡ 1 (mod p); aᵖ mod p = 3⁷ ≡ 3 ≡ 3 (mod 7); a^(p−1) mod p = 3⁶ ≡ 1 (mod 7).

Key terms

Prime
A whole number greater than 1 with no divisors other than 1 and itself.

Frequently asked questions

What does the theorem say?

For a prime p, aᵖ − a is divisible by p; if p does not divide a, then a^(p−1) leaves remainder 1.

Does the converse hold?

No, Carmichael numbers such as 561 pass the test without being prime.

How is it used in practice?

In the Fermat primality test and in RSA.

What if p divides a?

Then a^(p−1) ≡ 0 (mod p), but aᵖ ≡ a still holds.

Sources

  1. Wolfram MathWorld: Fermat's little theorem
  2. OpenStax: Contemporary Mathematics

Cite this calculator

Speedy Calculator. (2026). Fermat’s Little Theorem Calculator. Speedy Calculator. https://speedycalculator.com/calculators/math/fermats-little-theorem/