If a ring is a UFD, its irreducible elements are exactly its prime elements.
Show that the reverse is not true. Give a nontrivial counterexample.
Hint: Consider the ring $\mathbb{Z} + X\, \mathbb{Q}[X]$.
Note: in the following solution "denominator" of a rational number always means the denominator of its fraction simplified to lowest terms.
Let $R:= \mathbb{Z} + X\, \mathbb{Q}[X]$, whose only units are $R^\times = \{+1, -1\}$.
We show that if $a$ is reducible in $\mathbb{Q}[X]$, which means that $a = q r$ with $\deg(q), \deg(r) \ge 1$, then it is reducible in $R$. \begin{equation*} a(X) = \Bigl(\sum_{i=1}^{m} q_i X^i\Bigr) \cdot \Bigl(\sum_{j=1}^{n} r_j X^j\Bigr) \quad \text{with $m, n \ge 1$}\, . \end{equation*} Since $q_0 r_0 = a_0 \in \mathbb{Z}$, there is an $c \in\mathbb{Q}$ with $c q_0, \frac{r_0}{c} \in \mathbb{Z}$. To be more precise $c = \frac{\text{Denominator of $q_0$}}{\text{Denominator of $r_0$}}$.
Then \begin{equation*} a(X) = \Bigl(\sum_{i=1}^{m} c q_i X^i\Bigr) \cdot \Bigl(\sum_{j=1}^{n} \frac{r_j}{c} X^j\Bigr) \, , \end{equation*} so $q, r \in R$ and not units, so $a$ is reducible in $R$.
Let $a, b, p \in R$ with $p$ irreducible and $p \mid a b$. Now we look at the problem in $\mathbb{Q}[X]$. As shown, $p$ cannot be reducible $\mathbb{Q}[X]$, so it must be a unit or irreducible.
We first treat the case that it is irreducible in $\mathbb{Q}[X]$. Since we are now in an UFD if $p \mid a b$ it follows that $p \mid a$ or $p \mid b$. Assume without loss of generality that $p \mid a$. So there is an $u\in\mathbb{Q}[X]$ with $p u =a$. It follows that $p_0 \cdot u_0 = a_0 \in \mathbb{Z}$. If $u_0 \not\in \mathbb{Z}$, there is $c \in \mathbb{Z}$ (the denominator of $u_0$) for which $\frac{p_0}{c}\in\mathbb{Z}$ and so $\frac{p}{c}\in R$, which contradicts the assumption that $p$ is irreducible in $R$. But if $u_0 \in \mathbb{Z}$, also $u\in R$ and we have in $R$ (!) that $p$ divides $a$.
Now we treat the case that $p$ is a unit in $\mathbb{Q}[X]$. Since $(\mathbb{Q}[X])^\times = \mathbb{Q}\setminus\{0\}$ and $R \cap \mathbb{Q} = \mathbb{Z}$, it follows that $p\in\mathbb{Z}$ and since $p$ is irreducible, it has to be a prime number. If $p\mid ab$, it follows that $p_0 \mid a_0 b_0$ (again with $a_0, b_0\in \mathbb{Z}$), so $p_0\mid a_0$ or $p_0\mid b_0$ and therefore $p \mid a$ or $p \mid b$.
We have proven that all irreducible elements of $R$ are prime.
But $R$ is not an UFD, for example $$\frac{X^2}{6} = \frac{X}{2} \cdot \frac{X}{3} = \frac{X}{6}\cdot X \, .$$
Can somebody have a look if this solution is ok? I think the solution seems far too complicated. Either I've missed something obvious or there is a theorem which would make it much easier.
PS: What would be a trivial counterexample?