TITLE: Number of singular $2\times2$ matrices with distinct integer entries
QUESTION [12 upvotes]: Given an integer $n$, what is the total number of singular $2 \times 2$ matrices with distinct elements from $\{0,1,\ldots,n\}$?

Example:
a) For $n=6$, the numbers to be considered are $\{0,1,2,3,4,5,6\}$. So the valid matrices whose determinants equal $0$ are:
1)$$
        \begin{vmatrix}
        1 & 2 \\  
        3 & 6 \\       
        \end{vmatrix}=0
$$
2)$$
        \begin{vmatrix}
        1 & 3 \\  
        2 & 6 \\       
        \end{vmatrix}=0
$$
3)$$
        \begin{vmatrix}
        2 & 1 \\  
        6 & 3 \\       
        \end{vmatrix}=0
$$
4)$$
        \begin{vmatrix}
        2 & 4 \\  
        3 & 6 \\       
        \end{vmatrix}=0
$$,etc
like these there are 16 possible ways for n=6, So the answer is 16
b)For n=50 there are 5824 ways
c) For n=24, there are 920 ways
So I need To know the way of evaluating this problem

REPLY [7 votes]: Here's a start: If $\begin{vmatrix}a_1&a_2\\a_3&a_4\end{vmatrix}=0$ then also $\begin{vmatrix}a_{\sigma(1)}&a_{\sigma(2)}\\a_{\sigma(3)}&a_{\sigma(4)}\end{vmatrix}=0$ where $\sigma\in D_8\subset S_4$ with
$$D_8:=\langle(1\ 2\ 4\ 3),(1\ 4)\rangle.$$
This is the maximal subgroup of $S_4$ for which this holds, as it clearly doesn't hold for all $\sigma\in S_4$. Because the entries of the matrices are distinct the number of solutions is a multiple of $|D_8|=8$. Every such matrix with determinant zero allows for a unique permutation $\sigma\in D_8$ such that 
$$a_{\sigma(1)}<a_{\sigma(2)}<a_{\sigma(3)},$$
and from $a_1a_4=a_2a_3$ it follows without loss of generality that
$$a_1<a_2<a_3<a_4.$$

EDIT: Inspired by mfl's answer here's some work in progress (gotta run):
Let $\left(\begin{smallmatrix}a_1&a_2\\a_3&a_4\end{smallmatrix}\right)$ be such a matrix. Then after a permutation $\sigma\in D_8$ of the entries $a_1<a_2<a_3<a_4$ and $a_1a_4=a_2a_3$, so $a_3=ca_1$ and $a_4=ca_2$ for some scalar $c$. Because $ca_1$ and $ca_2$ are integers there exists an integer $b$ such that $c=\tfrac{b}{d}$ where $d:=\gcd(a_1,a_2)$. Because $a_2<a_3=ca_1$ and $ca_2=a_4\leq n$ it follows that
$$d\frac{a_2}{a_1}<b\leq d\frac{n}{a_2}.$$
Note also that $a_1\neq0$ because $a_3>a_2>0$, so $a_1\geq1$ and $a_2>1$, and that $a_2\leq n-2$.
Conversely, if $a_1$, $a_2$, and $b$ are integers such that $1<a_2\leq n-2$ and $1\leq a_1<a_2$ and 
$$d\frac{a_2}{a_1}<b\leq d\frac{n}{a_2},$$
where again $d=\gcd(a_1,a_2)$, then $a_3:=\tfrac{b}{d}a_1$ and $a_4:=\tfrac{b}{d}a_2$ satisfy $a_1a_4=a_2a_3$ and
$$a_3=\frac{b}{d}a_1>\frac{a_2}{a_1}a_1=a_2\qquad\text{ and }\qquad a_4=\frac{b}{d}a_2\leq\frac{n}{a_2}a_2=n,$$
and of course $a_3<a_4$ because $a_1<a_2$, so $a_1<a_2<a_3<a_4$. So now we can count the solutions.
The number of integers $b$ in the interval $(d\tfrac{a_2}{a_1},d\tfrac{n}{a_2}]$ is precisely 
$$\lfloor d\frac{n}{a_2}\rfloor-\lfloor d\frac{a_2}{a_1}\rfloor,$$
whenever the interval is nonempty, i.e. whenever $d\tfrac{n}{a_2}-d\tfrac{a_2}{a_1}\geq0$, or equivalently $a_1\geq\tfrac{a_2^2}{n}$. So the number of solutions is
$$\sum_{a_2=2}^{n-2}\sum_{a_1=\lceil\tfrac{a_2^2}{n}\rceil}^{a_2-1}
\lfloor d\frac{n}{a_2}\rfloor-\lfloor d\frac{a_2}{a_1}\rfloor.$$