The invariant factors are part of the structure of the module itself. You wouldn't be able to say much without looking at the structure of the module directly.
Let's take your 32 elements abelian group as an example.
If one had an abelian group of order 32 prepared, they might go about figuring out which of the listed groups it is by checking orders of elements. Finding an element of order 16, for example, would narrow it down to the top two possibilities.
Why did they generate that list using the factorization of 32? They were simply trying to write down every possible set of invariant factors. Because $(32)$ annihilates $M$, we know that $c_n$ is a divisor of 32 (because $(32)\subseteq ann(M)=(c_n)$.) But $c_{n-1}$ divides $c_n$, so it's going to be in that list of divisors of 32. If $c_{n-1}$ happened to be 4, well then $c_{n-2}$ would need to be a divisor of 4, etc. If you go on this way, remembering keeping the size of the group in mind, you will be able to list all possible lists of invariant numbers, as they did:
$$
32\\
2|16\\
4|8\\
2|4|4\\
2|2|8\\
2|2|2|4\\
2|2|2|2|2\\
$$
In a nutshell, if you can find anything that annihilates $M$, say $(x)$, the invariant factors have to be divisors of $x$.
It's probably going to be easier, though, if you first try to find the primary decomposition of $M$, and then compute the invariant factors from that. (I think that is possible... how was it done again...? Hmm...)
Best Answer
Here's an ugly argument that I know of (which works for abelian groups, and so I assume it works over arbitrary PID). You need to make three observations:
Once you have proven those, take a direct sum decomposition of $N$ into cylic $p$-submodules $N_1\oplus N_2\oplus\dots\oplus N_i$ (which exists by structure theorem of finitely generated modules over a PID), and use 1., 2. and 3. to obtain a decomposition $M=M_1\oplus\dots M_n\oplus M'$, where $M_i$ is the maximal cyclic $p$-submodule that contains the cyclic $p$-submodule $N_i$.
*by $p$-module I mean a module annihilated by some power of the prime $p$ in the PID $R$ (it's the primality of $p$ that matters, not irreducibility, for the total ordering of submodules, though the two coincide over PIDs, which is where you need to be anyway for the structure theorem to work)