Computing $7^{13} \mod 40$ I wanted to compute $7^{13} \mod 40$. I showed that 
$$7^{13} \equiv 2^{13} \equiv 2 \mod 5$$
and
$$7^{13} \equiv (-1)^{13} \equiv -1 \mod 8$$.
Therefore, I have that $7^{13} - 2$ is a multiple of $5$, whereas $7^{13} +1$ is a multiple of $8$. I wanted to make both equal, so I solved $-2 + 5k =  + 8n$ for natural numbers $n,k$ and found that $n = 9, k = 15$ gave a solution (just tried to make $3 + 8n$ a multiple of $5$. Therefore, I have that 
$$7^{13} \equiv -73 \equiv 7 \mod 40.$$
Is this correct? Moreover, is there an easier way? (I also tried to used the Euler totient function, but $\phi(40) = 16$, so $13 \equiv -3 \mod 16$, but I did not know how to proceed with this.)

The Carmichael function $\lambda$ is a stronger version of Euler totient function for this purpose which combines different prime factors by $\rm lcm$ rather than simple multiplication, and adjusts higher powers of $2$.
So $\lambda(40) = {\rm lcm}(\lambda(8),\lambda(5)) = {\rm lcm}(2,4) = 4$, and thus the cycle length of $7$ is divisible by $4$. Since $\gcd(7,40)=1$  and $13\equiv 1 \bmod 4$, this immediately gives $7^{13}\equiv 7 \bmod 40$.
