linear algebra question cong Suppose you are given a polynomial $p(x)=(x-a)(x-b)$, where $a\neq b$ and $a,b\in\mathbb{Z}$. How many equivalence classes of $\mathbb{Z}$ conjugate $2$ by $2$ matrices having $p$ as their characteristic polynomial are there? That is, for the equivalence relation $A$~$B$ iff $\exists S\in GL_{2}(\mathbb{Z})$ such that$S^{-1}AS=B$, how many equivalence classes are there with the characteristic polynomial $p$? I think there are finitely many, but I'm not sure exactly how many
 A: Let $A\in M_{2}(\mathbb{Z})$ be a matrix with eigenvalues $a,b\in\mathbb{Z}\ (a\neq b)$.  Since $a,b\in \mathbb{Z}$, we can find an  eigenvector $\left(\begin{array}{c}
e \\ 
f 
\end{array} \right)\in\mathbb{Z}^2$ associated to $a$.$($Find first in $\mathbb{Q}^2$ then multiply the vector to obtain a vector in $\mathbb{Z}^2)$.
We can suppose wlog that $mdc(e,f)=1$. 
Thus, exist $y,x\in\mathbb{Z}^2$ such that $ey-fx=1$. 
Therefore, $\det\left(\begin{array}{cc}
e & x \\ 
f & y
\end{array} \right)=1$. Let $S=\left(\begin{array}{cc}
e & x \\ 
f & y
\end{array} \right)$.
Now, notice that $S^{-1}AS\left(\begin{array}{c}
1  \\ 
0 
\end{array} \right)=\left(\begin{array}{c}
a  \\ 
0 
\end{array} \right)$. Thus, $S^{-1}AS$ is an upper triangular matrix and since is similar to $A$, this matrix must be $S^{-1}AS=\left(\begin{array}{cc}
a & d \\ 
0 & b
\end{array} \right)$.
Therefore every matrix like $A$ is similar to a triangular matrix $\left(\begin{array}{cc}
a & d \\ 
0 & b
\end{array} \right)$, with some $d\in\mathbb{Z}$. 
Now, we only need to find out when these triangular matrices are equivalent.
Suppose $S^{-1}\left(\begin{array}{cc}
a & d \\ 
0 & b
\end{array} \right)S=\left(\begin{array}{cc}
a & d' \\ 
0 & b
\end{array} \right)$ and $\det(S)=\pm 1$. 
Notice that $S\left(\begin{array}{c}
1  \\ 
0 
\end{array} \right)$ is a eigenvector of $\left(\begin{array}{cc}
a & d \\ 
0 & b
\end{array} \right)$ associated to $a$. Thus, $S=\left(\begin{array}{cc}
g & h \\ 
0 & i
\end{array} \right)$. 
Since $\det(S)=gi=\pm 1$ then $\{g,i\}\subset\{-1,1\}$.
Since $S^{-1}\left(\begin{array}{cc}
a & d \\ 
0 & b
\end{array} \right)S=(-S)^{-1}\left(\begin{array}{cc}
a & d \\ 
0 & b
\end{array} \right)(-S)$ wlog we may assume $g=1$ and $i=\pm1$.
Thus, $S=\left(\begin{array}{cc}
1 & h \\ 
0 & \pm 1
\end{array} \right)$ and $S^{-1}=\left(\begin{array}{cc}
1 & \mp h \\ 
0 & \pm 1
\end{array} \right)$.
Thus, $\left(\begin{array}{cc}
a & d' \\ 
0 & b
\end{array} \right)=S^{-1}\left(\begin{array}{cc}
a & d \\ 
0 & b
\end{array} \right)S=\left(\begin{array}{cc}
a & (a-b)h\pm d \\ 
0 & b
\end{array} \right)$. 
Therefore, $d'\mp d=(a-b)h=|a-b|h'$. Thus, $d'\equiv\ \pm d\ mod\ |a-b|$.
Of course if $d'\equiv\ \pm d\ mod\ |a-b|$, we can reverse the steps and prove that $\left(\begin{array}{cc}
a & d \\ 
0 & b
\end{array} \right)$ is equivalent to $\left(\begin{array}{cc}
a & d' \\ 
0 & b
\end{array} \right)$. Thus a necessary and sufficient condition for the equivalence of these two triangular matrices is $d'\equiv\ \pm d\ mod\ |a-b|$.
Finally, if $|a-b|$ is even the number of classes is $\dfrac{|a-b|}{2}+1$. If $|a-b|$ is odd the number is $\dfrac{|a-b|+1}{2}$.
