Why $1\equiv a^{p-1} \mod p$? Let $\mathbb{Z}_p^*$, where $p$ is prime and let $a\in\mathbb{Z}_p^*$.
Consider the following equation:$$(p-1)! \equiv (p-1)! a^{p-1} \mod p$$
I've read that since $\gcd((p-1)!, p) = 1$ we can infer that $$a^{p-1} \equiv 1$$
So I have two questions:


*

*Why is it true that $\gcd ((p-1)!, p)= 1$? 

*Why can we infer that $a^{p-1} \equiv 1$?


If you write down $(p-1)!$ as $(p-1)\cdot(p-2)\cdot\cdot\cdot1$ you can easily notice that $p$ and $(p-1)!$ have no common factors. 
So $gcd((p-1)!,p) = 1$.
Now, knowing that:
$$ax \equiv b \mod(m) \implies x \equiv b \cdot a^{-1}  \mod(\frac{m}{gcd(m,a)})$$
you have the answer to your question.
