How to efficiently compute $17^{23} (\mod 31)$ by hand? I could use that $17^{2} \equiv 10 (\mod 31)$ and express $17^{23}$ as $17^{16}.17^{4}.17^{3} = (((17^2)^2)^2)^2.(17^2)^2.17^2.17$ and take advantage of the fact that I can more easily work with powers of ten ($17^2 \equiv 10 (\mod 31), (17^2)^2 \equiv 100 (\mod 31) \equiv 7 (\mod 31)$, etc.). While this makes the computation easier, I'm thinking there might be a better way to do this.

Modulo $31$ we have:
$$17^1 \equiv 17$$
$$17^2 \equiv 10 \text{ (because $289$ mod $31$ is $10$)}$$
$$17^4 \equiv (10)^2 \equiv 7 \text{ (because $100$ mod $31$ is $7$)}$$
$$17^8 \equiv (7)^2 \equiv 18 \text{ (Similar)}$$
$$17^{16} \equiv (18)^2 \equiv 14 $$
And $17^{23} \equiv 17^{16} \cdot 17^4 \cdot 17^2 \cdot 17^1$.
So $17^{23} \equiv 14 \cdot 7 \cdot 10 \cdot 17$. We note that $7\cdot 10 = 70 \equiv 8 \mod 31$, so  $17^{23} \equiv 14 \cdot  8 \cdot  17$, and $8\cdot 17 = 136 \equiv 12 \mod 31$, so $17^{23} \equiv 14 \cdot 12 \mod 31$, and $14 \cdot 12 = 168 \equiv 13 \mod 31$.
