TITLE: Basic question about mod
QUESTION [7 upvotes]: I'm having a tough time understanding why $(a^x \bmod p)^y \bmod p$ is equal to $a^{xy}\bmod p$.
Does this have a mathematical proof? Please advise.

REPLY [3 votes]: All you need to prove is that if $a \equiv b \mod n$ then $a^m \equiv b^m \mod n$.
While this follows by induction from the product rule as mentined above, you can also prove it directly the following way:
In $n$ divides $a-b$, then $n$ also divides
$$(a-b)[a^{n-1}+a^{n-2}b+...+b^{n-1}]= a^n-b^n \,.$$