Fermat's little theorem. Let pp be a prime and a∈Za\in\mathbb Z. Then

ap≡a(modp).a^p\equiv a\pmod p.

If p∤ap\nmid a, this is equivalent to

ap−1≡1(modp).a^{p-1}\equiv 1\pmod p.

Here x≡y(modp)x\equiv y\pmod p means that p∣(x−y)p\mid(x-y).

Remarks

The second form follows from applied to the (Z/pZ)×(\mathbb Z/p\mathbb Z)^\times, which has order p−1p-1. The first form also covers the case p∣ap\mid a.

Examples
  • For p=7p=7 and a=3a=3, 36=729≡1(mod7)3^6=729\equiv1\pmod 7.
  • If p∤ap\nmid a, then ap−2a^{p-2} is a multiplicative inverse of aa modulo pp.