Number of units in the ring of matrices I want to know about the number of units in the ring of all matrices of order $n\times n$ over the field of order $p$,
where $p$ is a prime.
I read in one my book that the order of $\mathit{GL}(n,\mathbb Z_p)$ is $(p^n-1)(p^n-p)(p^n-p^2)\dots (p^n-p^{n-1})$.
I think this is the required number of units in the group $M_n(\mathbb Z_p)$.
But I can't deduce it.
Also I have a question what will be the result if p is not prime i.e composite.?
Hope to get help.
Thanks.
Edit: My question for prime modulus $p$ is already been discussed here.
So I would like to know about the case when the modulus is composite.
 A: Invertibility of $n\times n$ matrices over $\mathbb{Z}/m\mathbb{Z}$ is equivalent to checking the determinant of the matrix is coprime to $m$.  Note that the determinant can be computed as if the entries are integers, and then reduced mod $m$, since the determinant is a polynomial in the matrix entries.
This leads to a fairly simple analysis via Chinese remainder theorem when $m$ is a product of distinct primes.  See for example the previous Question about counting where $m=26$.  As Jyrki Lahtonen outlines in the Comments on that Question, any pairing of invertible matrix $A$ mod $2$ and invertible matrix $B$ mod $13$ can be combined per CRT to give invertible matrix $C$ mod $26$.  Thus the count of invertible matrices mod $m=pq$ where $p,q$ are distinct primes is the product of the counts for invertible matrices mod $p$ and mod $q$.
Indeed this reduction works for any factorization of $m$ into factors that are coprime (not necessarily prime factors), provided we know how to count the invertible matrices mod those coprime factors separately.  Chinese remainder theorem again allows us to piece together invertible pairs of matrices in the coprime factor moduli.
So the hard part of the counting for general moduli concerns the case of repeated prime factors, i.e. for $m = p^k$.  A short classroom note (on Linear Ciphers) that gives upper and lower bounds on the count is K. Pommerening's The Number of Invertible Matrices over a Residue Class Ring.
Formulas for the exact count of invertible matrices (with composite moduli) are developed in On the Keyspace of the Hill Cipher by Overbey, Traves, and Wojdylo (2005).
By the observations above it suffices to give their formula (Thm. 2.2.2) for a prime power modulus, with minor changes in notation for consistency:
$$ \text{When } m=p^k,\;\; |\mathit{GL}(n,\mathbb{Z}/m\mathbb{Z})| = p^{(k-1)n^2} \prod_{i=0}^{n-1} (p^n - p^i) .$$
Here $\mathit{GL}(n,\mathbb{Z}/m\mathbb{Z})$ is the "general linear" group of $n\times n$ invertible matrices with entries in $\mathbb{Z}/m\mathbb{Z}$.  So the order of that (multiplicative) group of matrices is precisely the count of invertible matrices under discussion.
Note that when $k=1$ the above formula simplifies immediately to the case already established for a prime modulus $\mathbb{Z}/p\mathbb{Z}$.
