When are quadratic rings of integers unique factorization domains? Let $D$ be a square free integer. Let $R_D$ be the integral closure of $\mathbb{Z}$ in the field $\mathbb{Q}(\sqrt{D})$. 
For some values $D$, the ring $R_D$ is a $UFD$, but not for all. For example, the Gaussian integers $R_{-1}$ are a $UFD$ whereas the ring $R_{-5}$ is not. There are several ways to show this, including computing the class number of $R_D$. However, all the proofs I've seen feel ad hoc and unintuitive.
According to the Stark-Heegner theorem, for $D<0$, the ring $R_D$ is a $UFD$ if and only if 
$$D \in \{-1,-2,-3,-7,-11,-19,-43,-67,-163\}.$$
Is there any intuitive reason why this should be a complete list? Ideally there would be a structural reason - coming up with a separate proof for each $D$ in the list is deeply unsatisfying to me. 
 A: I do think there is an intuitive reason, and it has to do with the number 41. You know that $n^2 + n + 41$ is prime for all $0 \leq n < 40$? Of course it's composite for $n = 41$ (and less obviously for $n = 40$).
Notice that $$\left(\frac{1}{2} - \frac{\sqrt{-163}}{2}\right)\left(\frac{1}{2} + \frac{\sqrt{-163}}{2}\right) = 41,$$ $$\left(\frac{3}{2} - \frac{\sqrt{-163}}{2}\right)\left(\frac{3}{2} + \frac{\sqrt{-163}}{2}\right) = 43,$$ $$\left(\frac{5}{2} - \frac{\sqrt{-163}}{2}\right)\left(\frac{5}{2} + \frac{\sqrt{-163}}{2}\right) = 47,$$ and so on and so forth to $$\left(\frac{79}{2} - \frac{\sqrt{-163}}{2}\right)\left(\frac{79}{2} + \frac{\sqrt{-163}}{2}\right) = 1601.$$
What are the other numbers $d$ such that $n^2 + n + d$ gives primes for $0 \leq n < d$? 2, 3, 5, 11, 17, see OEIS A014556. And then $-4d + 1$ gives $-7, -11, -19, -43, -67$, and $-163$ corresponds to 41.
No higher number $d$ meets this requirement, and thus does not correspond to a Heegner number.
EDIT: Corrected per a comment.
A: I wouldn't be so quick to discount the value of going through the list one by one. For this post, let's stipulate $D < 0$ throughout.
You've noticed $-2$ is the only even value on there, right? If $D$ is even, then $D = (\sqrt D)^2$, which is obvious enough. But if $D$ is even and composite, it means that $N(z) = 2$ for $z \in \mathcal{O}_{\mathbb{Q}(\sqrt D)}$ is impossible. So then $2$ is irreducible, yet $D = 2 \times x = (\sqrt D)^2$, where $x \in \mathcal{O}_{\mathbb{Q}(\sqrt D)}$ also.
You've also noticed that $-5$ is not on the list either. Neither is $-13$, $-17$, $-29$, etc. What these numbers have in common, besides being odd, is that they are congruent to $3 \bmod 4$ (remember that congruence gets "flipped" for negative numbers, so $-3 \equiv 1 \bmod 4$, not $3 \bmod 4$).
So, if $D \equiv 3 \bmod 4$, then $N(1 + \sqrt D) = -D + 1$, which is even. But in this domain, it turns out that $N(z) = 2$ is also impossible. Which means that $-D + 1$ has at least two distinct factorizations. Thus $D = -5$ gives us the classic example $6 = 2 \times 3 = (1 - \sqrt{-5})(1 + \sqrt{-5})$.
Now let's say $D \equiv 1 \bmod 4$ instead. Then it's still the case that $-D + 1 = (1 - \sqrt{D})(1 + \sqrt{D})$, but... $$\frac{1 - \sqrt{D}}{2}, \frac{1 + \sqrt{D}}{2}$$ are also algebraic integers, both with minimal polynomial $$x^2 - x + \frac{-D + 1}{4},$$ e.g., $$\frac{1 - \sqrt{-43}}{2}, \frac{1 + \sqrt{-43}}{2}$$ both have the polynomial $x^2 - x + 11$.
Therefore, the full factorization of $44$ in this domain is not $(1 - \sqrt{-43})(1 + \sqrt{-43})$ but $$2^2 \left(\frac{1 - \sqrt{-43}}{2}\right) \left(\frac{1 + \sqrt{-43}}{2}\right).$$
Why this doesn't work out for $D \leq -167$ is quite a bit more involved, maybe someone else will address that.
