Fermat's little theorem
and the second equality uses Fermat's little theorem, which is