Fermats Little Theorem Calculator

Fermat's Little Theorem Calculator

Verify a^(p-1) mod p for a prime p and integer a with a live modular arithmetic check.

Last updated: June 2026 | By Patchworkr Team

Modular Exponent Check
Enter an integer base a and a prime modulus p. The calculator checks the congruence directly with modular exponentiation.
Result
Congruence
2^6 ≡ 1 (mod 7)
Because p is prime and a is not divisible by p, Fermat's Little Theorem gives residue 1.
Expected residue for the theorem: 1

What the theorem says

If p is prime and a is not divisible by p, then a^(p-1) is congruent to 1 modulo p. This is one of the basic results behind modular arithmetic.

When it does not apply

If p is not prime, or if a is a multiple of p, the theorem does not give the value 1. The calculator explains that case directly.

Formula and example

a^(p - 1) ≡ 1 (mod p)

Example: 3^(7 - 1) mod 7 = 1, so the theorem holds.

Worked Example

Check a = 3 and p = 7.

1. Confirm that 7 is prime.

2. Compute 3^(7 - 1) mod 7 = 3^6 mod 7.

3. Reduce the power using modular exponentiation.

Final answer: 1

Frequently Asked Questions

Why does the result become 1?

That is exactly what Fermat's Little Theorem guarantees when p is prime and a is not divisible by p.

Can p be 1 or 0?

No. The modulus must be a prime number greater than 1.

Does the calculator handle negative a?

Yes. Negative integers are reduced modulo p before exponentiation.

Why use modular exponentiation?

It avoids huge intermediate values while still computing the correct residue.

Related Tools