What is the average determinant of a matrix in $M_{2}(\mathbb{Z}/n\mathbb{Z})$? Given a finite collection of matrices, it is natural to consider the average determinant of a matrix in such a collection. For example, an interesting problem involving the average determinant of a binary matrix is given in the following link: Fun Linear Algebra Problems.
So it is natural to consider the average determinant of a matrix in $M_{k}(R)$, the full ring of $k \times k$ matrices over a finite ring $R$. In particular, I am interested in the average determinant of a matrix in $M_{2}(\mathbb{Z} / n \mathbb{Z})$ using the 'usual' operations of addition and division, i.e. the arithmetic mean of $\{ \det(A) : A \in  M_{2}(\mathbb{Z} / n \mathbb{Z}) \}$ with respect to the 'usual' operations of addition and division. Letting $a_{n}$ denote the arithmetic mean of this set, we have that:
$$\left( a_{n} : n \in \mathbb{N}_{\geq 2} \right) = \left( \frac{3}{8}, \frac{8}{9}, \frac{21}{16}, \frac{48}{25}, \frac{161}{72}, \frac{144}{49}, \frac{105}{32}, \frac{104}{27}, \frac{171}{40}, \frac{600}{121}, \ldots  \right).$$
The On-Line Encyclopedia of Integer Sequences (OEIS) does not 'recognize' the sequence $$\left( 3, 8, 21, 48, 161, 144, 105, 104, 171, 600, \ldots \right)$$ of numerators of $\left( a_{n} : n \in \mathbb{N}_{\geq 2} \right)$, and the sequence of denominators of $\left( a_{n} : n \in \mathbb{N}_{\geq 2} \right)$ is not currently in the OEIS. It appears that the sequence $$\left( a_{n} \cdot 2 n^2 : n \in \mathbb{N}_{\geq 2} \right) = \left(  3, 16, 42, 96, 161, 288, 420, 624, 855, \ldots \right)$$ is an integer sequence, but this sequence is not currently in the OEIS. However, it appears that the sequence $$\left( \left\lfloor a_{n} \right\rfloor : n \in \mathbb{N}_{\geq 2} \right) = \left( 0, 0, 1, 1, 2, 2, 3, 3, 4, 4, 5, 5, \ldots \right)$$ is equal to the OEIS sequence A004526.
It is natural to ask:
(1) What is $a_{n}$? Can the sequence $\left( a_{n} : n \in \mathbb{N}_{\geq 2} \right)$ be expressed in a natural way in terms of 'well-known' integer sequences? Is there a simple combinatorial/number-theoretic formula for $a_{n}$ which may be used to compute $a_{n}$ more efficiently compared to a brute-force algorithm for computing $a_{n}$?
(2) Is there a simple way of proving that $\left\lfloor a_{n} \right\rfloor = \left\lfloor \frac{n-2}{2} \right\rfloor$? Is there a simple way of generalizing this result?
(3) Are there any interesting number-theoretic or combinatorial properties associated with the average determinant or immanant of a matrix in $M_{k}(\mathbb{Z} / n \mathbb{Z})$?
 A: Let $X_n=\{A\in M_2(\mathbb Z/n\mathbb Z)\mid \det A\neq 0\}$.
Then if we define $T:X\to X$ as $T\begin{pmatrix}a&b\\c&d\end{pmatrix}=\begin{pmatrix}b&a\\d&c\end{pmatrix}$, we see that $TA=A$ is impossible if $\det A\neq 0$.
But $T\circ T=I_X$ and $\det TA=-\det A\neq 0$, so $\det A + \det TA=n$ when the addition is done in $\mathbb Z$. 
So $\sum_{A\in M_2} \det A = \sum_{A\in X_n} \det A=\frac{1}{2}\sum_{A\in X_n} n = \frac{n}{2}|X_n|$.
So your average is:
$$\frac{|X_n|}{2n^3}$$
So you are need to count the number of matrices without non-zero determinant.
OEIS has the sequence $|X_n|$: A005353.
The function $f(n)=n^4-|X_n|$, counting the elements in $M_2$ with determinant zero, is a multiplicative function (which you can see via a Chinese remainder theorem argument), and OEIS says that  $$f(p^e)=p^{2e-1}\left(p^{e+1}-p^{e}-1\right)=p^{3e}\left(1-\frac{1}{p}-\frac{1}{p^{e+1}}\right)$$
(Initially, I got the formula for $f$ wrong, giving the wrong answer.)
We can see pretty obviously that $0<f(n)<n^3$.
So $$\frac{n-1}{2}=\frac{n^4-n^3}{2n^3}<a_n=\frac{|X_n|}{2n^3}=\frac{n^4-f(n)}{2n^3}<\frac{n^4}{2n^3}=\frac{n}{2}$$
This lets you show that $\lfloor a_n\rfloor = \left\lfloor \frac{n-1}{2}\right\rfloor$. We also can get that $2a_n-n+1\in(0,1)$ gets arbitrarily close to both $0$ and $1$ and it is not hard to show the set $\{2a_n-n+1\}$ is dense in $(0,1)$.
