Finitely generated module over PID; Dummit and Foote, Exercise 12.1.12 Let $R$ be a PID and let $p$ be a prime in $R$. 
(a) Let $M$ be a finitely generated torsion $R$-module. Use the previous exercise to prove that $p^{k-1}M/p^kM \cong F^{n_k} $ where $F$ is the field $R/(p)$ and $n_k$ is the number of elementary divisors of $M$ which are powers $p^a$ with $a \ge k$.
(b) Suppose $M_1$ and $M_2$ are isomorphic finitely generated torsion $R$-modules. Use (a) to prove that, for every $ k \ge 0$, $M_1$ and $M_2$ have the same number of elementary divisors $p^a$ with $a \ge k$. Prove that this implies $M_1$ and $M_2$ have the same set of elementary divisors.
I am referring to the exercise 12.1.12 of Dummit-Foote book Abstract Algebra. I have proved the part (a) and that $M_1$ and $M_2$ have the same number of elementary divisors with $p^a$ with $a \ge k$. 

I have difficulties to prove that $M_1$ and $M_2$ have the same set of elementary divisors. 

Can anyone help me...thanks in advance....
 A: You already know the following: 

For every prime $p\in R$, and for every $k\ge 0$, $M_1$ and $M_2$ have the same number of elementary divisors $p^a$ with $a\ge k$. 

Let's prove that this is enough to conclude that $M_1$ and $M_2$ have the same set of elementary divisors.   
Suppose that $p^{k_1}$ is an elementary divisor of $M_1$. First let's assume that $k_1$ is a maximal exponent with this property. Note that $M_2$ has no elementary divisor of the form $p^a$ with $a>k_1$, otherwise $M_1$ would have (at least) one of that form, a contradiction with the maximality of $k_1$. Instead $M_2$ has an elementary divisor of the form $p^{k_1}$, and their number is the same as the one of elementary divisors of the form $p^{k_1}$ in $M_1$. 
Now suppose that $p^{k_2}$ is an elementary divisor of $M_1$ with $k_2<k_1$, and there is no other elementary divisor of $M_1$ of the form $p^a$ with $k_2<a<k_1$. (That is, $p^{k_2}$ is the next elementary divisor of $M_1$ less that $p^{k_1}$.) As before one can show that there is no elementary divisor of $M_2$ of the form $p^a$ with $k_2<a<k_1$, but there is at least one of the form $p^{k_2}$, and their number is the same as the one of elementary divisors of the form $p^{k_2}$ in $M_1$. 
Continue this way and show that the elementary divisors of the form $p^a$ are the same for both modules. Since $p$ is an arbitrary prime you are done.
A: Suppose that $M$ is $p$-primary and decomposes as a direct sum of cyclic modules $$\tag 1 M=Ax_1\oplus Ax_2\oplus\cdots \oplus Ax_n$$
Say $(0:x_i)=(p^{k_i})$, and $k_1\geqslant k_2\geqslant \cdots\geqslant k_n$. Note then that in $p^nM=\widehat M$ the only summands that survive are those for which $k_i>n$. Since $p$ is irreducible, you know that $k=A/(p)$ is a field, and $\overline M_n=\widehat M/p\widehat M$ is a $k$ module, i.e. $k$-vector space. Now observe that in $\overline M_n$ the classes of the $p^nx_i$ with $k_i>n$ are nonzero, and hence the direct sum decomposition (which is inherited in the quotient) gives directly that $d_n=\sum_{k_i>n} 1=\dim_k\overline M_n$ -- this is because we have our vector space decomposed into cyclic one dimensional subspaces, and $\dim(V\oplus W)=\dim V+\dim W$. This gives that the number is independent of the decomposition $(1)$, so yields uniqueness. In particular, if $M\simeq N$, $\overline M_n\simeq \overline N_n$ so their dimensions coincide. 
There are lots of things I glossed over in the above. It is very important that you verify the details and carry out proofs when necessary. To conclude, note that the number of $(0:x_i)$ with $k_i$ exactly equal to $n$ is $d_n-d_{n-1}$. 
