Math

Instant, private, and free

Fermat's Little Theorem Calculator.

Calculate a^(p−1) modulo p for a prime p.

On-device calculationNo signup
01

Set your values

Results update as you type.

a mod p: 7

a mod p

7
a^(p−1) mod p: 1

a^(p−1) mod p

1
Theorem result: yes

Theorem result

yes

Results update automatically as you type.

Use Cases

Verify Fermat's Little Theorem

Check that a^(p-1) mod p equals 1 for any base a not divisible by prime p. Useful for students and educators to confirm the theorem.

Example: For a=3 and p=7, 3^6 mod 7 = 1.

Simplify modular exponentiation

When computing large powers modulo a prime, reduce the exponent using Fermat's theorem to make calculations easier. This calculator provides the result directly.

Example: To compute 5^100 mod 11, use 5^10 ≡ 1, so 5^100 = (5^10)^10 ≡ 1.

Frequently Asked Questions

What does Fermat's Little Theorem state?
Fermat's Little Theorem states that if p is a prime number and a is any integer not divisible by p, then a^(p-1) ≡ 1 (mod p). This calculator computes the exact remainder when a^(p-1) is divided by p.
What if 'a' is a multiple of p?
If a is a multiple of p, then a mod p is 0, so a^(p-1) mod p is 0. The theorem's condition requires a not divisible by p for the result to be 1. This calculator will still compute the correct remainder.
Can I use this calculator for non-prime p?
No, the calculator is designed for prime p only. If you enter a non-prime p, the result may not follow Fermat's Little Theorem. The theorem only holds for prime p.

Tips & Common Mistakes

Tips

  • Ensure p is a prime number; otherwise, the theorem does not apply.
  • If a is divisible by p, the result will be 0, not 1.
  • Use this calculator to quickly check your manual modular arithmetic.
  • Remember that a^(p-1) mod p is always 1 for a not divisible by p.

Common Mistakes to Avoid

  • Entering a non-prime value for p, which invalidates the theorem.
  • Forgetting that a must not be divisible by p for the result to be 1.
  • Confusing Fermat's Little Theorem with Euler's theorem, which applies to composite moduli.

Last updated: August 13, 2026