Home · Everyday · Bases, Binary & Logic · Fermat's Little Theorem Calculator
Fermat's Little Theorem Calculator
Check Fermat's little theorem for your a and p: a^(p−1) ≡ 1 (mod p) whenever p is prime and p ∤ a.
What this calculator does
Check Fermat's little theorem for your a and p: a^(p−1) ≡ 1 (mod p) whenever p is prime and p ∤ a. Where a measure is involved, US and metric units are both accepted — flip the unit toggle and the figures convert with the same definitions the formula uses. Every result on this page is computed from the formula stated below, with no hidden rounding steps.
The formula and method
Fermat's little theorem: if p is prime and p does not divide a, then a^(p−1) ≡ 1 (mod p).
The check evaluates both sides exactly with modular exponentiation.
The converse is false — passing the test does not prove p prime (Carmichael numbers exist).
Worked example
With the example inputs this page opens with (base a 2, prime p 7), the result is 1 — a^(p−1) mod p. Fermat's little theorem: for prime p and a not divisible by p, a^(p−1) ≡ 1 (mod p) — and indeed the computation gives 1. It is a one-way test: composites that also pass for a given a are called Fermat pseudoprimes to that base.
Quick reference
| Base a | a^(p−1) mod p |
|---|---|
| 1 | 1 |
| 1.6 | 1 |
| 2 | 1 |
| 2.5 | 1 |
| 3 | 1 |
| 4 | 1 |
Computed with the same formulas as the calculator above — enter any values there for figures beyond this table.
Common questions
How does the Fermat's Little Theorem Calculator work?
Check Fermat's little theorem for your a and p: a^(p−1) ≡ 1 (mod p) whenever p is prime and p ∤ a. A · p → a^(p−1) mod p and verdict. The result updates as you type, and the formula and method on this page state the exact definitions used, so you can reproduce the calculation by hand.
What inputs does the Fermat's Little Theorem Calculator need?
A · p → a^(p−1) mod p and verdict. Invalid entries — such as a zero denominator, an out-of-range value or a malformed list — produce a plain-language message instead of a misleading number.
Is the Fermat's Little Theorem Calculator free to use?
Yes. It runs entirely in your browser with no sign-up, and the same calculator is available as an embeddable widget via the Embed button, so it can be placed on another site with its calculation intact.