TITLE: In Fermat's little theorem, if mod is not prime?
QUESTION [5 upvotes]: Today I learned about Fermat's little theorem
It says -  

Fermat's little theorem states that if p is a prime number, then for
  any integer a, the number a p − a is an integer multiple of p. In the
  notation of modular arithmetic, this is expressed as $a^p \equiv a \mod p$ 

It considers "p" as a prime numbers. But what if "p" is not prime? Then if those cases how to solve this type of problems?

REPLY [4 votes]: There is the Carmichael Theorem, which provides results stronger than Euler's Theorem, which generalizes Fermat's Little Theorem to non-prime modulo.