# Invertible matrices modulo $29$. [duplicate]

Consider the $n\times n$ matrices with elements in $\mathbb{Z}_{29}$. How many of these are invertible?

In total there are $29^{n^2}$ matrices of of dimension $n\times n$. Now I need to find how many of these are invertible modulo $29$. My plan of attack is to find how many are not invertible and then subtract this amount. A matrix $A$ is not invertible modulo 29 if and only if $$\det{(A)}\in\mathbb{Z}_{29}^\times\iff \gcd{(\det{A},29)}=1.$$

Now I'm not really sure how to advance any further. Clearly if $\det{A}<29$ then the gcd is $1$ since $29$ is prime, but how do we analyse larger determinants?

• Try considering $LU$ decomposition. – lhf Feb 11 '16 at 13:52
• I don't know if this helps, but... For any $k\in\Bbb Z_{29}^\times$, consider the function $f_k:\Bbb Z_{29}^{n\times n}$ that maps a matrix $A$ to $kA$. Since $\det(kA)=k^{29}\det(A)=k\det(A)$, the function $f_k$ maps bijectively the matrices with det $1$ to the matrices with det $k$. So, for each $k\in\Bbb Z_{29}^\times$ there are the same number of matrices with det $k$. – ajotatxe Feb 11 '16 at 13:57

## 2 Answers

You know by linear algebra that, if $\mathbb K$ is a field, a matrix $A\in \mathcal{M}_{n\times n}(\Bbb K)$ is invertible if and only if its columns are linearly independent.

Now: if $\#\mathbb K=q$, how many $n$-tuples $(v_1,\cdots,v_n)$ of linearly independent vectors are there?

• $v_1$ can be anything except $0$. So it can be chosen in $q^n-1$ possible ways.

• once you've chosen $v_1$, $v_2$ can be anything except a vector in $\operatorname{Span}(v_1)$, hence $q^n-q$ candidates for $v_2$.

• once you've chosen $v_1$ and $v_2$, $v_3$ can be anything except a vector in $\operatorname{Span}(v_1,v_2)$, so there are $q^n-q^2$ choices of $v_3$.

If you continue you get $$\#\operatorname{GL}(n,\Bbb K)=\prod_{k=0}^{n-1}(q^n-q^k)=q^{n(n-1)/2}\prod_{k=1}^{n}(q^k-1)$$

In your case, $q=29$.

You can check https://en.wikipedia.org/wiki/General_linear_group where there is a formula and a little explanation for the number of matrices in GL(n,q), which is $$(q^n-1)(q^n-q)(q^n-q^2)\cdots(q^n-q^{n-1})$$