In a UFD if $x$ is irreducible, then $(x)$ is prime I know how to show that if $(x)$ is prime ideal then $x$ irreducible element. 
I know the converse is true if the ring is a UFD, but how to show it?

i.e. in a UFD, if $x$ is irreducible, then $(x)$ is a prime ideal.

 A: Let $R$ be a UFD.
Suppose $p$ is an irreducible element of $R$.
In order to show that $p$ is a prime we will show that $(p)$ is a prime ideal of $R$.
We know that $(p) \neq \{0\}$ because an irreducible element is nonzero.
Also $(p) \neq R$ because an irreducible element is not a unit.
Suppose the product $ab$ of two elements $a, b \in R$ is an element of $(p)$.
Then $ab = mp$ for some $m \in R$.
First suppose $m = 0$.
Then $ab = 0$.
Since $R$ is an integral domain then either $a = 0$ or  $b = 0$.
If $a = 0$ then $a \in (p)$ and if $b = 0$ then $b \in (p)$.
This means $(p)$ is a prime ideal and $p$ is prime.
Now suppose $m \neq 0$, but $m$ is a unit.
This means that $mp$ is an associate of $p$.
Then since $a, b \in R$, which is a UFD, then we have
\begin{align*}
a = y_1 \cdots y_r \\
b = x_1 \cdots x_m
\end{align*}
for some irreducibles $y_k, x_l$.
So $$(y_1 \cdots y_r)(x_1 \cdots x_m) = mp$$
By the uniqueness of the product of irreducibles, $mp$ is equal to $y_k$ for some $k$ or $x_l$ for some $l$.
If $mp$ is equal to $y_k$ for some $k$ then $mp\ |\ a$.
If $mp$ is equal to $x_l$ for some $l$ then $mp\ |\ b$.
It follows that $a \in (p)$ or $b \in (p)$ and $(p)$ is a prime ideal.
In either case $p$ is prime in $R$.
Lastly suppose $m \neq 0$ and $m$ is not a unit.
Then since $m,a, b \in R$, which is a UFD, then we have
\begin{align*}
m = z_1 \cdots z_n \\
a = y_1 \cdots y_r \\
b = x_1 \cdots x_m
\end{align*}
for some irreducibles $z_i, y_k, x_l$.
So $$(y_1 \cdots y_r)(x_1 \cdots x_m) = (z_1 \cdots z_n)p$$
By the uniqueness of the product of irreducibles, $p$ or an associate of $p$ is equal to $y_k$ for some $k$ or $x_l$ for some $l$.
If $p$ or an associate of $p$ is equal to $y_k$ for some $k$ then $p\ |\ a$.
If $p$ or an associate of $p$ is equal to $x_l$ for some $l$ then $p\ |\ b$.
It follows that $a \in (p)$ or $b \in (p)$ and $(p)$ is a prime ideal.
In either case $p$ is prime in $R$.
A: Hint: Take any $ab\in (x)$ and consider the factorisations of $a$, $b$ and $ab$ into irreducible elements.
A: Let $R$ be a unique factorization domain.  Let's call two elements in $R$ associate if one can be multiplied by a unit to get the other.  This defines an equivalence relation on $R$, and you can easily check that an associate of an irreducible element is irreducible.  Let $P$ be a complete set of representatives of irreducible elements of $R$ under this relation.  
Then to say that $R$ is a unique factorization domain is to say that every nonzero element $x$ in $R$ can be written as 
$$u_x\prod\limits_{p \in P} p^{x_p}$$
for a unit $u$ and nonnegative integers $x_p$, and that $u_x$ and $x_p$ are uniquely determined.  This is a finite product.
Let's say that an irreducible element $q \in P$ occurs in a given element $x$ if $x_q \geq 1$.  Obviously, $q$ divides $x$ if and only if $q$ occurs in $x$.  If $a, b$ are nonzero elements of $R$, we have 
$$u_{ab} \prod\limits_{p \in P} p^{(ab)_p}= ab =(u_a \prod\limits_{p \in P} p^{a_p})(u_b \prod\limits_{p \in P} p^{b_p}) = u_au_b \prod\limits_{p \in P} p^{a_p + b_p}$$
so by uniqueness, $u_{ab} = u_au_b$ and $a_p + b_p = (ab)_p$ for all $p$.  It follows from here that if an irreducible element in $P$ occurs in a product $ab$, it must occur in either $a$ or $b$.  
This shows the elements of $P$ are prime.  But every irreducible element of $R$ is associate to a unique element of $P$, so every irreducible element of $R$ is prime.
What's also interesting is the converse: if in an integral domain, every nonzero element is a product of irreducibles, and if every irreducible is prime, then you are in a unique factorization domain.
