# Finitely generated torsion module over a PID

I have a question about modules over PID's from Lang's Algebra p. 152.

Assume $E$ is a f.g. non-zero torsion module over a pid $R$. Lang shows that $E\cong R/(q_i)\oplus\cdot \cdot \cdot \oplus R/(q_r)$ where $q_1,...,q_r$ are non-zero non-units of $R$ and $q_1|q_2|\cdot \cdot \cdot |q_r.$

Now suppose $p$ is a prime number and let $E_p$ be the set of elements of $E$ killed by a power of $p$. Lang claims that the dimension of the vector space $E_p$ over $R/(p)$ is equal to the number of terms $R/(q_i)$ such that $p$ divides $q_i$. Can someone help me see this?

Ok. So, let's actually explicitly calculate what $E_{p}$ is. Let $n$ be the largest integer such that $p$ does not divide $q_{n}$. Hence, $p$ divides $q_{n+1}, \ldots, q_{r}$ but does not divide $q_{1}, \ldots, q_{n}$ (because the $q_{i}$ are arranged in order of divisiblity.) My claim is that, as a $R$ module, (and hence as an $R/(p)$ vector space since $(p)$ annihilates the module), $$E_{p} = \oplus_{i=n+1}^{r} \left(\frac{q_{i}}{p}\right)/\left(q_{i}\right).$$
Let's call the module on the right, $M$. Then, by definition, $M$ is a submodule of $E$ consisting of elements that are killed by $p$. Hence, $M \subseteq E_{p}.$ On the other hand, suppose $$\sum_{i=1} \overline{r_{i}} \in E_{p}$$ where $r_{i} \in R$ and $\overline{r_{i}}$ is its projection in $R/(q_{i}).$ Then, we have $p\overline{r_{i}} = 0$ and hence $pr_{i} \in (q_{i})$. For $i = 1, \ldots, n$, since $p$ does not divide $q_{i}$ and hence $\text{g.c.d}(p, q_{i}) = 1.$ Hence, $q_{i}$ must divide $r_{i}$ and hence $\overline{r_{i}} = 0.$ This holds for $i = 1, \ldots, n$.
On the other hand, for $i = n+1, \ldots, r$, we still have $pr_{i} \in (q_{i})$ and because $p$ divides $q_{i}$, this implies $r_{i} \in \left(\frac{q_{i}}{p}\right).$ Hence, we have for such $i$, $\overline{r_{i}} \in \left(\frac{q_{i}}{p}\right)/\left(q_{i}\right)$. This gives us $E_{p} \subseteq M$ and hence $E_{p} = M.$
Now, we can count the dimension of each $\left(\frac{q_{i}}{p}\right)/\left(q_{i}\right)$. A basis for this as an $R/(p)$-vector space is given by the image of $1 \in R$ in $R/(q_{i}).$ Hence, each summand in $E_{p}$ is one-dimensional, and the number of summands is the number of $q_{i}$ that $p$ divides. This is what we wanted.