<s>[INST] Factors of the numbers of the form $a^2+nb^2$ 
Let $N=a^2+nb^2$ with $\gcd(a,b) =1$ and $n \in \mathbb{Z^+}$. If $N=xy$ where $x$ and $y$ are relatively prime numbers, in what condition can $x$ and $y$ be also written in the same form as $N$ (i.e, $c^2+nd^2$) ? How can we prove it? 

The above statement is true for sum of two squares (i.e, the case $n=1$), which has been proved by Fermat and Euler $($Here $ \text{is Euler's proof, see Proposition} \ 4)$ using Infinite Descent and Brahmagupta's Identity. But can it be generalized?  
Any help will be appreciated.
Thanks.
 [/INST] This is true when $a^2 + n b^2$ is of class number one ( well, the form class number of the discriminant $-4n$). I refer to the number of (equivalence classes of) primitive binary quadratic forms with that discriminant, $-4n.$ Even in this case, we need to be cautious when there are also imprimitive forms of that discriminant. This is all in Dickson's little book, page 91
An easy example would be $x^2 + 6 y^2,$ where the other class of this discriminant is $2 x^2 + 3 y^2.$ Now, $ 3 \cdot 11 = 33 = 9 + 6 \cdot 4.$ Neither of $3,11$ can be expressed as $x^2 + 6 y^2.$ However, in accordance with Dickson, $11 = 2 \cdot 4 + 3,$ and $3 = 2 \cdot 0 + 3.$ This example even gives a formula,
$$ (2u^2 + 3 v^2)(2x^2 + 3 y^2) = (2ux+3vy)^2 + 6 (uy-vx)^2  $$
There are always such formulas, this is Gauss composition, but no guarantee that the whole thng will be pretty. The most elegant ones happen when we have already written the forms ready for Dirichlet's presentation of composition. This can be found, for example, in the book by Cox, Primes of the Form $x^2 + n y^2.$
 
Dirichlet on composition: we usually write the forms of discriminant $-44$ as $x^2 + 11 y^2,$ $3 x^2 + 2 xy + 4 y^2,$ $3 x^2 - 2 xy + 4 y^2.$ However, the first is $SL_2 \mathbb Z$ equivalent to $27 x^2 + 8 xy + y^2,$ the second form to $3 x^2 + 8 xy + 9 y^2,$ the third (its "opposite" class) to 
$9 x^2 + 8 xy + 3 y^2.$ And composition comes out well:
$$ (3 x^2 + 8xy + 9 y^2)(9 z^2 + 8zw + 3 w^2) = 27 X^2 + 8XY + Y^2, $$
where
$$ X =xz-yw, \; \; Y=3xw+9yz+8yw $$
This is on page 49 in the first edition of Cox, which had a typo in the formula for $X.$ Corrected in the second edition, see if I can paste in an excerpt.

</s>