Cyclic Modules over a PID 
Let $R$ be a PID and $M$ be an $R$-module. 
  
  
*
  
*If $M$ is finitely generated then show that $M$ is cyclic if and only if $M/PM$ is cyclic for every prime ideal $P$ of $R$. 
  
*Show that the previous statement need not be true if $M$ is not finitely generated.
  

This problem was given in an exam I took which I couldn't really tackle. Here cyclic module means a module generated by a single element. 
Now for the first part, I think the main tool to apply here is the structure theorem of finitely generated modules over a PID. According to the theorem we can write $$M\cong R^n\oplus R/(a_1)\oplus \cdots \oplus R/(a_m)$$ where $a_i\in R, a_1|a_2|\dots |a_m$. Now since $R$ is a PID $P=(p)$ for some prime element $p$ of $R$. To prove the assertion I want to show $n=1$ and $m=0$. So if there is any $a_i$'s occurring then choosing a prime $q$ dividing $a_i$ and looking at $M/(q)M$ should give a module which is not cyclic. Thus we shouldn't have any $a_i$'s occurring, and then we are left with only $R^n$ but if the quotient module is cyclic then this forces $n=1$ because the quotient of $R^n$ should again be free on $n$ generators. But I'm having trouble writing down the argument, because even though I see intuitively quotienting by a prime $q$ dividing $a_i$ should give some nonzero module given by the quotient $N/(q)N$ where $N=R/(a_i)$. But how does one write this concretely? Any help would be appreciated. 
About the second part, I have no idea. I tried to think of the simplest PID, $\mathbb{Z}$. I considered $\mathbb{Z}[X]$ the polynomial ring, which is an infinitely generated module over the integers. This is not cyclic clearly. But as an example this doesn't work as $\mathbb{Z}[X]/p\mathbb{Z}[X]$ is not cyclic as well. So I'd like some help finding a counterexample. But more importantly, how does one approach such a situation? I mean the counterexample I tried to think was because I just tried to simply negate all the conditions that work for the first part, namely finite generation. And I took a module which is generated by countably many things $1,X, X^2, \dots$ but that doesn't work, so how does one think of something like that?
 A: As pointed out in the comments the statement as written is true independent of whether or not the module is finitely generated.
Namely, as $R$ is integral, we get that the zero ideal is prime and as $M\cong M/(0)M$ we are done if we assume that the quotient $M/PM$ is cyclic for all prime ideals $P$ in $R$.
We may be tempted to replace "$P$ prime ideal" by "$P$ a nonzero prime ideal". That alone is not a good idea. That change would still give a false statement. That is, because there are PIDs where the zero ideal is the only prime ideal (the case iff $R$ is a field). Hence, the statement about quotients is vacuously for $R$ being a field. However, there are noncyclic vector spaces (any vector space of dimension greater or equal to $2$).
Hence, the correct statement should be:

Let $R$ be a PID which is not a field and $M$ be a finitely generated $R$-module. Then
  $M$ is cyclic if and only if $M/PM$ is cyclic for every nonzero prime ideal $P$ of $R$. 

If $M$ is cyclic, then clearly the quotient is cyclic as well (as if $M=(a)$, then $M/PM = (a+PM)$).
Let us now assume that $M/PM$ is cyclic for every nonzero prime ideal $P$ of $R$. By the structure theorem for finitely generated module over a PID, we know that there exist $n,m\in \mathbb{N}$ and $a_1,\dots, a_m \in R\setminus (\{0\} \cup R^\times)$ such that $a_i$ divides $a_{i+1}$ in $R$ and 
$$ M \cong R^n \oplus R/(a_1) \oplus \dots \oplus R/(a_m) $$
as $R$-modules.
Pick $p\in R$ a prime such that $p$ divides $a_1$ (and hence also all the other $a_i$). Then we get
$$ (a_1) M = \left((p) R^n \right) \oplus \left( (p) R/(a_1) \right) \oplus \dots \left( (p) R/(a_m) \right) = \left((p) R^n \right) \oplus 0 \oplus \dots \oplus 0.$$
This implies
$$ M/(p)M \cong \left[R^n \oplus R/(a_1) \oplus \dots \oplus R/(a_m) \right] / \left[ \left((p) R^n \right) \oplus 0 \oplus \dots \oplus 0\right]  
\cong \left(R^n / (p) R^n \right) \oplus R/(a_1) \oplus \dots \oplus R/(a_m)
\cong (R/(p) R)^{\oplus n} \oplus R/(a_1) \oplus \dots \oplus R/(a_m).$$
We show the following statement:

Let $R$ be a PID, $a,b\in R$. Then $R/(a_1) \oplus R/(a_2)$ is cyclic implies $(a_1) + (a_2) = R$. 

Let $R/(a_1) \oplus R/(a_2)$ be cyclic. Let $(x+(a_1), y+(a_2)) \in R/(a_1) \oplus R/(a_2)$ be a generator. Then there exists $r\in R$ such that
$$ (rx+(a_1), ry+(a_2))=r(x+(a_1), y+(a_2)) =(1+(a_1), 0+ (a_2)).$$
Thus, we get $ry\in (a_2)$ and there exists $\tilde{a}\in (a_1)$ such that
$$ 1= rx + \tilde{a}. $$
Hence, we get
$$ y = y\cdot 1 = \tilde{a}y + ryx \in (a_1)+(a_2). $$
Let $z\in R$. Then there exists $s\in R$ such that
$$ (sx+(a_1), sy+(a_2)) = s (x+(a_1), y+ (a_2)) = (0+(a_1), z+(a_2)). $$
This implies $z\in sy + (a_2) \subseteq (a_1)+(a_2)$. As $z$ was an arbitrary element in $R$, this implies $R=(a_1)+(a_2).$ $\blacksquare$
As $p\vert a_1$ and $a_i \vert a_{i+1}$, this immediately implies that $m=1, n=0$ or $n=0,n=1$. Note that $M$ is cyclic for $m=1, n=0$ and for $m=0, n=1$. $\square$
Now let us now turn to the case where $M$ is not finitely generated. We consider $R=\mathbb{Z}$ and $M=\mathbb{Q}$. For any nonzero prime ideal $P\subset \mathbb{Z}$ we have $P \mathbb{Q}= \mathbb{Q}$ and thus
$$ M/PM = M/M \cong 0 $$
is cyclic. However, $\mathbb{Q}$ is not a cyclic $\mathbb{Z}$-module. Indeed, assume it was cyclic. Then there exists a generator $p/q\in \mathbb{Q}$ ($p,q$ coprime) of $\mathbb{Q}$. Pick $n\in \mathbb{N}_{\geq 1}$ which is coprime to $q$. As $p/q$ generates $\mathbb{Q}$, there exists $m\in \mathbb{Z}$ such that
$$ \frac{1}{n} = m \frac{p}{q} = \frac{mp}{q}. $$
This implies
$$ mpn = q. $$
This is a contradiction as $n$ and $q$ are coprime.
A: I think this should be true for every ring $R$. More precisely... If $M$  is finitely generated then we can write $$M=Rx_1+\cdots + R x_n,$$ for suitable elements $x_i\in M$. We have a map $\phi\colon R\longrightarrow M$ taking $r\longmapsto r(x_1+\cdots + x_n)$. Observe that $M$ is cyclic if and only if $\phi$ is subjective, i.e. $\mathsf{Coker}(\phi)=0$. Now, we have a SES $$R\rightarrow M\rightarrow\mathsf{Coker}(\phi)\rightarrow 0,$$ so tensorizing by $-\otimes_RR/\mathfrak p$ we get the SES$$R/\mathfrak p\rightarrow M/\mathfrak p M\rightarrow\mathsf{Coker}(\phi)/\mathfrak p\mathsf{Coker}(\phi)\rightarrow 0.$$ By assumption, $M/\mathfrak p M$ is cyclic, so the map $R/\mathfrak p \rightarrow M/\mathfrak p M$ is subjective and $\mathsf{Coker}(\phi)=\mathfrak p\mathsf{Coker}(\phi)=0$. Now, thanks to Nakayama's Lemma, we get $\mathsf{Coker}(\phi)=0$.
