Method for finding the number of matrices in $M_2(\mathbb{Z}_3)$ whose determinant is $1$ I just came across a question which asks to find all the $2 \times 2$ matrices in $\mathbb{Z}_3$ whose determinant is $1$. I know that since there are only three elements in $\mathbb{Z}_3$, it is feasible to work out the problem by counting the number of correct combinations of elements. (And, though I'm not sure about my calculations, I think the answer is $20$.)
But what if there were more elements to be looked into? Then surely this pathological process wouldn't come very handy. So my question is...

Is there any shorter method for finding out the answer of this question which also works well in other (general) cases?

Thanks and regards.  
 A: First count the number of matrices with non-zero determinant. Do it column by column: the first column can be any non-zero vector, so that gives you $3^2-1$ possibilities. The second column can be any vector that does not lie in the span of the first (the determinant is 0 if and only if the two columns are linearly dependent), so you have $3^2-3$ possibilities for the second column. So that's 8*6=48 matrices with non-zero determinant.
Now, the determinant function is a surjective group homomorphism from the group of all invertible matrices to $(\mathbb{Z}/3\mathbb{Z})^\times$, so its kernel has size equal to the size of the domain / size of the image, i.e. 48/2=24.
This works in complete generality: the number of invertible matrices in $M_k(\mathbb{Z}/p\mathbb{Z})$ ($p$ a prime number) is
$$
(p^k-1)(p^k-p)(p^k-p^2)\cdots (p^k-p^{k-1}),
$$
and the number of matrices with determinant 1 is therefore that divided by $p-1$.
A: Hint: Let $A_i$ be the set of matrices with determinant $i$. 


*

*Show that $|A_i| = |A_j|$ for $i,j \neq 0$   

*Show that $|A_0| = 3^3+3^2 - 3$.

*Show that $\sum |A_i| = 3^4$.   
This works for all primes, and becomes a faster way to count the number of matrices.
