Let $R$ be a UFD. Suppose that $a$ and $b$ are nonzero nonunit elements of $R$. If $d_1$ and $d_2$ are gcds of $a$ and $b$, show that $d_1$ and $d_2$ are associates
I have tried to solve this problem, but I am not quite sure what I have done. Is this the way? If so, are there any missing details? UFDs are being a bit complicated for me.
Since $R$ is a UFD, we can write $a=up_1^{m_1}\cdots p_k^{m_k}$ and $b=vp_1^{n_1}\cdots p_k^{n_k}$, where $p_i$'s are irreducible elements nonasocciates and $u,v$ are units in $R$ ($m_i, n_i \in \mathbb{Z}^+$). Then $d_1=p_1^{l_1}\cdots p_k^{l_k}$ and $d_2=p_1^{r_1}\cdots p_k^{r_k}$, where $l_i$ and $r_i$ are the smallest of $m_i$ and $n_i$. But note that $l_i=r_i$ for all $i$. So $d_1|d_2$ and $d_2|d_1$. But we know that in an integral domain two elements are associates iff they divides mutualy. Completing the "proof".