Fermat's Little Theorem

Fermat's Little Theorem states, if \(p\) is a prime number and \(a\) is an integer, \(a^p\equiv a\) (mod \(p\)). The theorem itself is used and is very helpful when testing numbers to see if they are not prime. It can be easy to see whether a small number is not prime however, with big numbers it can be difficult. One of the most important things to note is that the theorem does not tell whether a number is prime but it does show if a number is not prime. Therefore, the famous theorem also states that if \(p\) does not divide \(a\), then \(a^{p-1}\equiv\) \(1\) (mod \(p\)). 

Although this is known as Fermat's Theorem, surprisingly this was not proven by Fermat. Fermat decided not to prove it because the amount of pages and work it would take to complete it. Euler was the first mathematician to have a proof published in 1749. A picture of the proof is shown below. 
We can now look at an example, let's say \(a=3\) and \(p=7\), using Fermat's Theorem we should get that \(3^{7-1}\equiv1\) (mod \(7\)) which then simplifies to \(3^6\equiv1\) (mod \(7\)). When computing this we will end up with \(\frac{729}{7}\), which does come out to have a remainder of \(1\). This theorem does show to be true for all prime numbers however, it is not only true for prime numbers. There are special cases where the theorem works for a number that is not prime, if the non-prime number ha