Counting matrices based on determinant and trace Let $p$ be an odd prime number and $T_p$ is the following set of $2 \times 2$ matrices:
$$ T_p =  \left\{ A = \begin{bmatrix}
 a & b \\ 
 c & a
\end{bmatrix}\ \Biggm|a,b,c \in \{0,1,2,...(p-1)\} \right\}$$
then how to prove that the number $k$ of $A$ in $T_p$ such that the trace of A is not divisible by $p$ but the $det(A)$ is divisible by $p$, is $k=(p-1)^2$ ?
 A: There are p-1 choices for $a$ (not $0$).  Given $a$, the determinant is $a^2-bc$ and since $\mathbb{Z}_p$ is a field you can solve $a^2-bc=0$ for $c$ unless $b=0$, so $p-1$ choices for $b$.  That makes $(p-1)^2$ total.
A: Here's a different point of view that leads to the same answer as Ross's.
Think of the matrices as being matrices over the field of $p$ elements by reducing the entries modulo $p$. The determinant is divisible by $p$ (that is, $0$ modulo $p$) if and only if the rows of the matrix do not form a basis for $\mathbf{F}_p^2$, if ando nly if the rows are not linearly independent, if and only if one row is a multiple of the other.
To get trace that is not zero, you just need to avoid $a=0$, since $2a\equiv 0\pmod{p}$ if and only if $a\equiv 0 \pmod{p}$ (since $p$ is odd). Having chosen $a$ and an arbitrary $b$, the only way for the determinant to be a multiple of $p$ is if $(c,a) = k(a,b)$ for some $k\in\mathbf{F}_p$ (operation done modulo $p$). If $b=0$, then no choice of $c$ will do, since $a\neq 0$. So $b\neq 0$. If $b\neq 0$, then the only $k$ that can possibly work is $k\equiv ba^{-1}\pmod{p}$, which forces the value of $c$. So you have one and only one such matrix for each nonzero choice of $b$.
In summary: $p-1$ choices for $a$; $p-1$ choices for $b$; once $a$ and $b$ are fixed (both necessarily nonzero), $c$ is forced by the condition that $(c,a)$ must be a scalar multiple of $(a,b)$. 
A: This essentially amounts to counting the cardinality of the following set: $T = \{a,b,c \in \mathbb{Z}_p: p \not | 2a \ \text{but} \ p|(a^2-bc) \ \text{for} \ a,b,c \in \mathbb{Z}_p \}$.
