# Equivalent definitions of Unique Factorization Domain

I'm working with the following definition:

A integral domain $$R$$ is said to be an unique factorization domain if
$$(i)$$ every non-unit, non-zero element $$r\in R$$ has a decomposition $$r = p_1\cdots p_n$$ where each $$p_i$$ is a irreducible element of $$R$$.
$$(ii)$$ if there exists another decomposition $$r = q_1\cdots q_m$$ of irreducibles, then $$n=m$$ and there exists a bijection between the $$p_i$$ and $$q_j$$ where each $$p_i$$ is associated to a $$q_j$$ in the sense that $$p_i = cq_j$$ for some unit element $$c$$.

I want to prove that this definition of an UFD is equivalent to a definition consisting of the (i) above together with
$$(ii)'$$ if $$a,b\in R$$ and $$p\in R$$ is an irreducible such that $$p|ab$$, then $$p|a$$ or $$p|b$$.

I have already proved $$(ii)\implies(ii)'$$ but I'm stuck in some details on the other direction.

If we have two decompositions $$r = p_1\cdots p_n = q_1\cdots q_m$$ then applying $$(ii)'$$ we have that every $$p_i$$ is associated with some $$q_j$$, but I don't know how to show that $$n=m$$. Can someone help?

You can use the cancellation property for domains, namely that if $$ab=ac$$ for non-zero elements, then $$a(b-c)=0$$ and therefore $$b-c=0$$, i.e. $$b=c$$.
Then you can make some argument by reductio or induction, like, if $$p_1\cdots p_n= q_1 \cdots q_m$$ irreducible, then $$p_1 = cq_k$$ for some $$k$$, so $$cp_2\cdots p_n = q_1\cdots q_{k-1}q_{k+1} \cdots q_m$$ etc.