Equality of powers of a $2\times2$ matrix over the integers modulo a prime number This is exercise 4 in section 2.6 in Basic Algebra 1 by Nathan Jacobson:

Let $A\in GL_2(\mathbb Z/p\mathbb Z)$ (that is, $A$ is an invertible 2 x 2 matrix with entries in $\mathbb Z/p\mathbb Z$, $p$ prime).
Show that $A^q = 1$ if $q = (p^2 - 1)(p^2 - p)$.
Show also that $A^{q + 2} = A^2$ for every $A \in M_2(\mathbb Z/p\mathbb Z)$ (the ring of matrices over $\mathbb Z/p\mathbb Z$).

The first part follows from the fact that $GL_2(\mathbb Z/p\mathbb Z)$ is a finite group of order $q$.
I'm having trouble with the second part and would appreciate any hint or answer. Thank you.

If $\det A=0$ we have $A^2=\hat aA$ for some $\hat a\in\mathbb Z/p\mathbb Z$ (why?). If $\hat a=\hat 0$ there is nothing to prove. For $\hat a\ne\hat0$ notice that $A^{q+2}={\hat a}^{q+1}A$. Now recall that $\hat a^{p-1}=\hat 1$, hence $\hat a^q=\hat 1$.
