Can we specifically prove that if $n\in\mathbb{Z^+}$ is composite and square-free then the ring of integers of $\mathbb{Q}(\sqrt{-n})$ is not a UFD? Let $\mathcal{O}_K$ be the ring of integers of a field $K$. I have learnt about the Baker-Heegner-Stark theorem, which implies that if $K=\mathbb{Q}(\sqrt{-n})$ with $n\in\mathbb{Z}^+$ square-free, then $\mathcal{O}_K$ is a UFD if and only if $n$ is a  Heegner number. However, I am interested in the possibility of obtaining an easier result: is it possible to prove that all Heegner numbers greater than $1$ are primes, with undergraduate mathematics?
 A: If $n = rs$ with integers $r,s>1$, then you have 2 different factorizations for $n$: $$n = -1 \sqrt{-n} \sqrt{-n} = rs.$$
We claim that $\sqrt{-n}$ is irreducible in $\mathcal{O}_{\mathbb{Q}(\sqrt{-n})}$, which will complete the argument.  If $\frac{a + b \sqrt{-n}}{2} \in \mathcal{O}_{\mathbb{Q}(\sqrt{-n})}$ is a divisor of $\sqrt{-n}$, where $a, b \in \mathbb{Z}$ and where we may assume $a \ge 0$, then the following must be an element of $\mathcal{O}_{\mathbb{Q}(\sqrt{-n})}$: $$2\frac{\sqrt{-n}}{a + b \sqrt{-n}} = 2\frac{\sqrt{-n}(a - b \sqrt{-n})}{a^2 + n b^2} = 2\frac{bn + a \sqrt{-n}}{a^2 + n b^2}.$$
Let $y := \frac{2a}{a^2 + nb^2}$ be the coefficient of $\sqrt{-n}$ of the last term above.  Clearly $0 \le y < 2$ (recall we assumed $a \ge 0$).  If $y=0$ then $a=0, b = \pm 1$ so the divisor we have found is trivial.  Otherwise $y = k/2$ for one of $k = 1,2,3$.  We may write: $$\frac{4}{k} = \frac{2}{y} = a + n \frac{b^2}{a}.$$ Both summands on the right side are positive, and $a$ is an integer. So if $k \ge 2$ then the left side is $\le 2$, we conclude that $a=1$ so the right side is $1 + n b^2 > 6$ (since $n$ is square-free composite) which is a contradiction.  If $k=1$, we have to step through a few more cases but we still get a contradiction.
Exercise: For real quadratic fields, the corresponding statement is false, e.g., the ring of integers of $\mathbb{Q}(\sqrt{6})$ is a unique factorization domain.  Where does this argument go wrong for real fields?
A: This is not quite enough. It could be that the two factorizations can each be refined into the same factorization. 
