TITLE: Number of matrices on $\mathbb Z_{p}$ with a given characteristic polynomial
QUESTION [11 upvotes]: How can I find the number of n×n matrices on $\mathbb Z_{p}$ with a given characteristic polynomial?
for example:
If $p$ is a prime number s.t. $p \equiv 3 \pmod 4$, then number of $2\times 2$ matrices on $\mathbb Z_{p}$ that their characteristic polynomial is $x^2+1$ would be equal to $p(p-1)$.
I don't have the proof of above example.

REPLY [4 votes]: $\newcommand{\Size}[1]{\left\lvert #1 \right\rvert}$For your special case, with characteristic polynomial $x^{2} + 1$ and $p \equiv 3 \pmod{4}$, the matrix is conjugate to its rational canonical form
$$
R =
\begin{bmatrix}
0 & 1\\
-1 & 0\\
\end{bmatrix}.
$$
So it is just a matter to see how many conjugates $R$ has. Alternatively, one may compute the centralizer of $R$, and discover that it is
$$
a I + b R
$$
with $a, b$ not both zero. So the centralizer has order $p^2 - 1$, hence $R$ has
$$\dfrac{\Size{\operatorname{GL}(2,p)}}{p^2 - 1}
=
\dfrac{(p^{2} - 1)(p^{2} - p)}{p^2 - 1}
= p(p-1)$$
conjugates.

When $p \equiv 1 \pmod{p}$, then the matrix can be put in the form
$$
R =
\begin{bmatrix}
a & 0\\
0 & -a\\
\end{bmatrix}.
$$
where $a$ is a primitive fourth root of unity. This time the centralizer has order $(p-1)^{2}$, as it consists of the diagonal matrices, hence $R$ has
$$\dfrac{\Size{\operatorname{GL}(2,p)}}{(p - 1)^{2}}
=
\dfrac{(p^{2} - 1)(p^{2} - p)}{(p - 1)^{2}}
= p(p+1)$$
conjugates.