Solution (source code)

= Solution

Use the norm $N(a+b\sqrt{-n})=a^2+nb^2$. If $n$ is composite, compare $n=(\sqrt{-n})(-\sqrt{-n})$ with an integer factorisation; if $n$ is prime, $n$ is odd and $n+1=(1+\sqrt{-n})(1-\sqrt{-n})$ has a nontrivial integer factorisation. Norm considerations show the relevant factors are irreducible and nonassociate, so unique factorisation fails.