invertible matrices whose columns have elements in $Z_{p^a}$, with $a$ changing I was trying to calculate the cardinality of the group of automorphisms of some abelian p-groups (let's say $Aut(H_p)$), and I saw many people using matrices to code the ring of endomorphisms of $H_p$, and then count the automorphisms by saying that a matrix is invertible if and only if its determinant is prime with $p$. How can I say that?
Could please someone explain this method, maybe with a simple example in dimension 2 to help me understanding? (For instance by taking $Z_4 x Z_{16}$ or $Z_9 x Z_{27}$)
 A: So let $R$ be a (commutative, unital) ring and $M_1, \ldots, M_n$ be $R$-modules. Note that in your case $R=\mathbb{Z}$ since any abelian group is an $\mathbb{Z}$-module. You might not know this "module" language, but do not be afraid, you can think about it as abelian groups.
Now put $M=M_1\oplus\cdots\oplus M_n$ and take any endomorphism $f:M\to M$. This endomorphism induces following "smaller" endomoprhisms
$$f_{ij}:M_j\to M_i$$
$$f_{ij}=\pi_i\circ f\circ \lambda_j$$
where $\pi_i:M\to M_i$ is a projection onto $i$-th coordinate and $\lambda_j:M_j\to M$ is an inclusion onto $j$-th coordinate.
So now you can write the collection $[f_{ij}]$ as a matrix. And then there's a lemma that states that the mapping $f\mapsto [f_{ij}]$ is a ring isomorphism. Note that on the left side (of the mapping) multiplication is given by composition while on the right side multiplication is given by matrix multiplication ($f_{ij}$ components are multiplied by composition again).
In other words every endomorphism can be uniquely expressed by smaller endomorphisms. Now for cyclic groups (note that every finitely generate abelian group is a product of cyclic groups) this is even simplier because every homomorphism between cyclic groups $f:C\to C'$ is uniquely determined by the value $f(1)$. On the other hand every value of $f(1)$ generates a homomorphism as long as the order of $f(1)$ divides the order of $C$. So now in your ring of matrices you can replace each small $f_{ij}$ homomorphism with a unique number $f_{ij}(1)$ (another lemma has to be proven here that the mapping $f_{ij}\mapsto f_{ij}(1)$ induces an isomorphism).
Now the last step is invertibility. If you look at those matrices as $\mathbb{Z_{p^a}}$-matrices then it can be shown that $M$ is invertible if and only if $p$ does not divide $\det(M)$ (note that values of $\det$ are in $\mathbb{Z}_{p^a}$). This follows from three facts:
(1) $\det$ preserves multiplication, so $$\det(M)\det(M^{-1})=\det(MM^{-1})=\det(I)=1\mod{p^a}$$
therefore invertible matrices have invertible $\det$.
(2) If $\det(M)$ is invertible in $\mathbb{Z}_{p^a}$ then $M^{-1}$ can be constructed via classical Cayley-Hamilton method.
Thus $M$ is invertible if and only if $\det(M)$ is invertible in $\mathbb{Z}_{p^a}$ and finally
(3) $a\in\mathbb{Z}_{p^a}$ is invertible if and only if $p$ does not divide $a$ (note: only true for prime $p$).
Thus $M$ is invertible if and only if $p$ (note without power) does not divide $\det(M)$, i.e. when $\det(M)\neq 0\mod{p}$.

Let's have a look at your example $M=\mathbb{Z}_4\oplus\mathbb{Z}_{16}$. You can write it down as a matrix
$$
\left[\begin{matrix}
a & b \\
c & d
\end{matrix}\right]
$$
So $a:\mathbb{Z}_4\to\mathbb{Z}_4$. There are $4$ possibilites for $a(1)$. $b:\mathbb{Z}_4\to\mathbb{Z}_{16}$ again $4$ possibilites for $b(1)$, $c:\mathbb{Z}_{16}\to\mathbb{Z}_4$ yields again $4$ possibilities and finally $d:\mathbb{Z}_{16}\to\mathbb{Z}_{16}$ gives $16$ possibilities. Any combination of those will give a new endomorphism, so all together there are $1024$ possibilites. Now you have to find those satisfying $ad-bc=1\mod{2}$ (note that $\neq 0$ is the same as $=1$ for $\mod{2}$). Ain't going to do that for you though. :D Good luck!
