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

apa(modp).a^p\equiv a\pmod p.

If pap\nmid a, this is equivalent to

ap11(modp).a^{p-1}\equiv 1\pmod p.

Here xy(modp)x\equiv y\pmod p means that p(xy)p\mid(x-y).

Remarks

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

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