Formula for the number of solutions of the congruence equation $xy-wz=0$ over $\mathbb{Z}_p$? The equation $xy-wz=0$ has 10 solutions over $\mathbb{Z}_2$ and 33 solutions over  $\mathbb{Z}_3$ (e.g. $x=y=2 \land w=z=1$ is one of the solutions). Is there any formula for the number of solutions of this equation over $\mathbb{Z}_p$ where $p$ is prime?
 A: The number of solutions is $(p-1)^3+(2p-1)^2$.
For there are $(p-1)^3$ ways to choose an ordered triple $(x,y,w)$ with entries from $0,1,\dots, p-1$, none equal to $0$. Given these, there is a unique $z$ modulo $p$ such that $xy-wz\equiv 0\pmod{p}$. This is because if $xy$ and $w$ are given, and $w\not\equiv 0\pmod{p}$,  the congruence $zw\equiv xy\pmod{p}$ has a unique solution $z$ modulo $p$. (Multiply both sides by the inverse of $w$ modulo $p$.)
And there are $2p-1$ ways to choose an ordered pair $(x,y)$ so that $xy$ is congruent to $0$; for each such choice there are $2p-1$ choices for $(w,z)$. 
A: Here is an alternate approach, but maybe not elementary.
Since $\mathbb Z_p$ is a field, a matrix in $\mathbb Z_p$ is invertible, if and only if the determinant is nonzero if and only if the rows are linearly independent.
Note that $xy-wz=0$ if and only if $\begin{bmatrix} x & w \\z &y \end{bmatrix}$ is not invertible.
Now, there are $p^4$ matrices of size $2 \times 2$ and entries in $\mathbb Z_p$. We now count how many are invertible. The following argument is the standard counting argument for the size of $GL_n(\mathbb Z_p)$.
The first row of an invertible matrix can be anything but $(0,0)$. Thus, we have $p^2-1$ choices for the first row.
The second row can be anything but a scalar multiple of the first row. As there are $p$ distinct scalar multiples of the first row (they are distinct since the first row is not $(0,0)$ we have $p^2-p$ choices for the second row.
Thus, there are $(p^2-1)(p^2-p)$ invertible $2 \times 2$ matrices with entries in $\mathbb Z_p$.
Therefore, the number of solutions of $xy-wz=0$ is equal with the number of non-invvertible matrices, which is
$$p^4-(p^2-1)(p^2-p)=p^4-(p-1)^2p(p+1)=p[p^3-(p-1)^2(p+1)]=p[p^3-(p^3-p^2-p+1)]=p(p^2+p-1)$$
