Fermat's Little Theorem Calculator

Compute aᵖ⁻¹ mod p, which is 1 when p is prime and a is not a multiple of p.

aᵖ⁻¹ mod p 1
Equals 1? yes

Formula: aᵖ⁻¹ ≡ 1 (mod p) for prime p

Step-by-step with your numbers:
1. Values used:
2. Base a = 3
3. Prime p = 7
4.
5. aᵖ⁻¹ mod p = 1
6. Equals 1? = yes
Did we solve your problem today?

Fermat's Little Theorem is a cornerstone of number theory and underpins primality testing and RSA.

The math behind it

If p is prime and a is not divisible by p, then aᵖ⁻¹ ≡ 1 (mod p). A result other than 1 proves p is composite.

Worked example

3⁶ mod 7 = 729 mod 7 = 1, confirming 7 is prime.

FAQ

Does result 1 prove p is prime?

Not always — some composites (Carmichael numbers) also pass; it's a strong hint, not a proof.