Fom wiki Fermat's little theorem, the theorem is as follows: If there exists an integer $a$ such that $ a^{p-1}\equiv 1\pmod p $ and for all primes $q$ dividing $p − 1$ one has ${\displaystyle a^{(p-1)/q}\not \equiv 1{\pmod {p}},}$ then $p$ is prime.
How to prove this theorem?