Skip to content
ENExplore Calculators

Fermat Little Theorem Calculator

Work out fermat little theorem instantly with clear inputs, formula shown and shareable results.

About Fermat Little Theorem Calculator

Fermat's little theorem says that if p is prime and a is not a multiple of p, then a^(p−1) ≡ 1 (mod p). The converse is not quite true: some composites, such as 561, pass for particular bases.

Formulas

Fermat's little theorem

a^(p−1) ≡ 1 (mod p) for prime p and a not divisible by p

Equivalent form

aᵖ ≡ a (mod p) for every a

Worked example

With the default values below, Fermat Little Theorem Calculator returns a^(p−1) mod p of 1. Change any input above and every figure here is recalculated in your browser.

Inputs used

Base aminimum 1
2
Modulus pminimum 2
17

Results

a^(p−1) mod p
1
Interpretation
Passes, and p really is prime
aᵖ mod p (equals a mod p when p is prime)
2
Primality by trial division
Yes, p is prime

Step by step

  1. 1Values used
  2. 2Fermat's little theorem
  3. 3Equivalent form
  4. 4a^(p−1) mod p= 1
  5. 5Interpretation= Passes, and p really is prime
  6. 6aᵖ mod p (equals a mod p when p is prime)= 2
  7. 7Primality by trial division= Yes, p is prime

Assumptions and limits

  • The result is derived only from the 2 inputs listed above. Anything not among them is not part of the calculation.
  • In particular, this calculator does not take inflation, tax, fees or charges or compounding frequency into account.
  • Figures are rounded for display to whole numbers, so totals built from several rounded parts can differ slightly from the unrounded arithmetic.

How these calculators are built and tested is described on the Methodology page. If a figure looks wrong, please report it.

Frequently Asked Questions

For a = 2, p = 17?

2¹⁶ mod 17 = 1, as the theorem requires since 17 is prime.

What is a Carmichael number?

A composite that passes the Fermat test for every coprime base. 561 is the smallest, which is why probabilistic tests use stronger checks.

Fermat Little Theorem Calculator – Calculate a^(p−1) mod p