TITLE: Matrices and prime numbers
QUESTION [7 upvotes]: Let $ p $ be a prime number and \begin{align} K=\left\{ \begin{pmatrix} a &b \\ 
 c& d \end{pmatrix} \mid a,b,c,d \in \left\{0,1,\ldots,p-1 \right\}, \right. & a+d \equiv 1 \!\!\!\! \pmod p, \\
& ad-bc \equiv 0 \!\!\!\! \pmod p \left.\vphantom{\begin{pmatrix} a &b \\ 
 c& d \end{pmatrix}} \right\}. \end{align}
  Determine $\operatorname{card}(K) $.

I have taken some particular cases: $ p=2,3,5 \text{ or } 7 $ and I've deduced that $\operatorname{card}(K)=p(p+1) $, but I can't extend the solution to the general case.

REPLY [3 votes]: Here's one way to count them.  Note that any such matrix can be built by one of the two following methods:
Method 1:

Select $a \in \{0,1,\dots,p-1\}$
Select a non-zero value for $b$
Solve for $d = 1 - a$, $c = \frac{ad}{b}$

Note that there are $p(p-1)$ matrices that we get from this method.
Method 2:

Set $b = 0$
$c$ may be freely chosen
Either set $a = 0$ and $d = 1$, or $a = 1$ and $d = 0$

There are exactly $2p$ matrices that we get from this method. 

In total, we thus have $p(p-1) + 2p = p(p+1)$ such matrices.