I want to calculate $A^B\bmod c$ (here $A$, $B$ and $c$ are all integers) and $B$ is very large like $10^{1000000}$ (such as a problem like FZU1759), and I have read many solutions about it but got the formula $A^x\equiv A^{x\bmod \varphi (c)+\varphi (c)} \bmod c (x\geq \varphi (c))$ without any proofs.
I know $A^x\equiv A^{x\bmod \varphi (c)} (\bmod\, c)$ $(x\geq \varphi (c))$ is right when $(A, c)=1$ because of the Euler's theorem. But when $(A, c)\neq1$ we should plus the $\varphi (c)$ and I don't know why it's correct.
For example, $4^{10}\equiv 4^{10 \bmod \varphi (6)+\varphi (6)}\equiv 4\pmod 6$, if I don't plus the $\varphi (6)$ I will get $0$.
Here $\varphi(x)$ is the Euler's totient function, and $(a,b)$ means the Greatest common divisor of $a$ and $b$.
I wonder how to prove it, thanks.