The quadratic form $x^2 + ny^2$ via prime factors Elementary algebra shows that the product of two numbers in the form $x^2 + ny^2$ again has the same form, since if $p = (a^2 + nb^2)$ and $q = (c^2 + nd^2)$, 
$$pq = (a^2 + nb^2)(c^2 + nd^2) = (ac \pm nbd)^2 + n(ad \mp bc)^2$$
My question is: Assuming that a number $z$ can be factored into primes of the form $x^2 + ny^2$, does every representation of $z$ in this form arise from repeated applications of this formula to the prime factors? 
 A: Well, no. It is a fair question, though. Even with class number one, we can begin with $1 + 3 = 4,$ although $x^2 + 3 y^2$ does not represent $2.$ The way Dickson would have talked about this is the imprimitive form of the same discriminant, namely $2 x^2 + 2 x y + 2 y^2.$
Staying with one class per genus, we have $1 + 5 = 6,$ although $x^2 + 5 y^2$ does not represent $2,3.$ This is a different phenomenon called Gauss composition. The trick for this one is that $2 x^2 + 2xy+3 y^2$ does represent $2,3,$ and there is a different identity that allows $(2 a^2 +2ab+ 3 b^2)(2 c^2 +2cd+ 3 d^2) = x^2 + 5y^2. $ You should probably be able to find such an identity by hand.
One of the simplest ones where identifying the primes involved becomes a mess is $x^2 + 11 y^2.$ It is a bit of a problem (although solved) to say which primes can be expressed as $x^2 + 11 y^2$ and which by $3 x^2 + 2 x y + 4 y^2,$ among those primes $p$ for which the Jacobi symbol $(-11 | p) = 1.$ But, seeing as the latter form does represent $3,5$ integrally, we are not surprised to see $4 + 11 = 15.$ In this case, you ought to involve the "opposite" form in $(3 a^2 + 2 a b + 4 b^2)(3 c^2 - 2 c d + 4 d^2) = x^2 + 11 y^2.$ The presence of the opposite form is what makes the set (of three "classes") into a group.
Well, that's a start.
A: Alright, the answer to the actual question asked is yes, as follows. I am taking a prime $p$ with $\gcd(p,n) = 1.$ Then I am demanding $u^2 + n v^2 = p.$ Next, I am taking some number, composite or prime, call it $Q,$ and demand about $pQ$ rather than $Q$ itself,
$$ pQ = r^2 + n s^2.    $$
First, we get
$$ \left( \frac{u}{v} \right)^2  \equiv \left( \frac{r}{s} \right)^2  \equiv -n \pmod p.  $$ Choose $\pm s$ so that
$$ \left( \frac{u}{v} \right)  \equiv \left( \frac{r}{s} \right)  \pmod p.   $$
So we have
$ u s \equiv v r \pmod p,$ or
$$ -us + vr \equiv 0 \pmod p.  $$
Next,
$$ p^2 Q = (ur + n v s)^2 + n (-us + v r)^2,   $$ and so
$$  Q = \left( \frac{ur + n v s}{p} \right)^2 + n \left(\frac{-us + v r}{p} \right)^2   $$ in integers.
Combine this once again with $p = u^2 + n v^2$ and you get back to $pQ = r^2 + n s^2$ as desired.
A: For another solution see my response at https://mathoverflow.net/questions/111489/the-quadratic-form-x2ny2-via-prime-factors/
