How to prove finite abelian group is direct sum of cyclic groups by using matrices over Euclidean domain? Exercise from Algebra, Chapter $0$ by Aluffi:
Prove



using this proposition:




I'm totally lost as to how to begin. How would we relate finite abelian groups to this theorem dealing with matrices over a Euclidean Domain?
My only guess to start would be to let $R=\mathbb Z$ (since abelian groups are $\mathbb Z$-modules). I know also that $M_{m,n}(\mathbb Z) \cong \mathrm{Hom}_{\mathbb Z-\mathrm{Mod}}(\mathbb Z^n, \mathbb Z^m)$ (which is itself a $\mathbb Z$-module).
Am I on the right track? Any ideas on how to go about this?
 A: Suppose $G$ is a finitely generated abelian group, generated by $m$ elements. Then it's a quotient of $\Bbb Z^m$, since $\Bbb Z^m$ is the free abelian group on $m$ generators. Next, the kernel of $\Bbb Z^m\to G$ is again a free abelian group, since every submodule of a free module over a PID is again free. So we can write a presentation for our group as $\Bbb Z^n\to \Bbb Z^m\to G$, and now we get to apply the theorem to the matrix which represents the first map.
Knowing this, see if you can figure out how to apply it for our situation of finite $G$. I'll leave the full answer in the following spoiler:

 In our case, as $G$ is finite, every generator has finite order, and thus $m=n$. So the matrix in question is square, and it cannot have any zeros on the diagonal - if it did, there would be an element of infinite order. So we have that $G\cong \Bbb Z/d_1\times \cdots \times \Bbb Z/d_n$. From here, you can use the standard fact that $\Bbb Z/a\cong \Bbb Z/b\times\Bbb Z/c$ if $a=bc$ and $(b,c)=1$ to verify the $p$-group assertion.

A: Here is a different approach, which fleshes out the idea I put forward in my comment. We'll think of $G$ as a $\Bbb Z$-module.  That is: $G$ denotes the group, $+$ denotes the group operation, and $n\cdot g := \underbrace{g + \cdots + g}_n$.  Let $\{g_1,\dots,g_n\}$ denote any (finite) generating set of $G$.
Every element of $G$ can be expressed in the form $g = \sum_{i=1}^n \alpha_i g_i$ for some coefficients $\alpha_i \in \Bbb Z$.  Equivalently, the map from $\Bbb Z^n$ to $G$ defined by $\phi: (\alpha_1,\dots,\alpha_n) \mapsto \sum_{i=1}^n \alpha_i g_i$ is an onto group homomorphism.  The kernel of this homomorphism corresponds to the relations that these generators satisfy: $(\alpha_1,\dots,\alpha_n)$ is in the kernel of the homomorphism iff $\sum_{i=1}^n \alpha_i g_i = 0$.
Because $G$ is a finite group, it can be finitely presented.  That is, there exist coefficients $p_{ij}$ for $1 \leq i \leq n$ and $1 \leq j \leq m$ such that
$$
G = \left \langle g_1,\dots,g_n : \sum_{i=1}^n p_{ij} g_i = 0 \text{ for } j = 1,\dots,m \right \rangle
$$
and we see that $\ker \phi = \langle (p_{1j}, \dots,p_{nj}) : 1 \leq j \leq m \rangle \subset \Bbb Z^n$.  Thus, by the first isomorphism theorem we have
$$
G \cong \Bbb Z^n / \langle (p_{1j}, \dots,p_{nj}) : 1 \leq j \leq m \rangle.
$$
We could put this another way: define $P:\Bbb Z^m \to \Bbb Z^n$ to be the "linear" map corresponding to the matrix whose entries are $p_{ij}$.  Then we have $G \cong \Bbb Z^n / \operatorname{im}(P)$.  
To connect this to the other answer, we might say that $G$ fits into the short exact sequence
$$
0 \to \Bbb Z^m \overset{P}\to \Bbb Z^n \overset{\phi}\to G \to 0
$$
Now, by Proposition 2.11 there exist invertible maps $J: \Bbb Z^m \to \Bbb Z^m$ and $K: \Bbb Z^n \to \Bbb Z^n$ such that $D= KPJ$ where $D$ is the diagonal matrix described (with entries in $\Bbb Z$).  Now, it suffices to observe that $\Bbb Z^m/\operatorname{im}(P)$ is isomorphic to $\Bbb Z^m/\operatorname{im}(D)$.  One way to see this is to consider the corresponding sequence
$$
0 \to \Bbb Z^m \overset{K\circ P\circ J}\to \Bbb Z^n \overset{J^{-1} \circ \phi}\to G \to 0
$$
