<s>[INST] calculating mod 7 Problem: Calculate $10^{10^{10}} \pmod 7$
According to Fermat's little theorem: $a^{p-1}\equiv1 \pmod p$, so $10^6\equiv1 \pmod 7$ and $10^n\equiv4 \pmod 6$, $n$ being any integer, why can we write $10^{10^{10}}\equiv10^4 \pmod 7$?
Similarly, if it's $10^n\equiv1 \pmod 3$, n being any integer, then wouldn't the equation become $10^{10^{10}}\equiv10^1\equiv3\pmod 7$? 
I'm confused on the translation phase.
Thanks
 [/INST] Let me see if I can make it clear
Starting with $10^6 \equiv 1 \mod 7$, we have
$$ \begin{align}
10^{12} &= \left(10^6\right)^2 \equiv 1^2 = 1 \mod 7\\
10^{18} &= \left(10^6\right)^3 \equiv 1^3 = 1 \mod 7\\
10^{24} &= \left(10^6\right)^4 \equiv 1^4 = 1 \mod 7\\
\cdots&
\end{align} $$
This tells us how to find $10^n \mod 7$. For example, if I want $10^{73} \mod 7$
$$
10^{73} = 10^{72 + 1} = 10^{72}\, 10 = \left(10^6\right)^{12} ~10 = 10 \mod 7 = 3
$$
In general when calculating $a^n \mod p$ where $p$ is a prime, we cast off multiples of $p-1$ from n i.e.
$$
a^n \mod p \equiv a^m \mod p ~~\hbox{where $n \equiv m \mod (p-1)$ }$$
Note: If $p$ is not a prime, then replace $p-1$ by $\phi(p)$
</s>