A question about two-square sum Let $a,b\in\mathbb{N}$ and $b$ is a factor of $a^2+(a+1)^2$, then there exists $x,y\in\mathbb{Z}$ such that $b=(bx+(2a+1)y)^2+y^2$.
I think it is true, but I have no idea to prove it. Thanks for any help.
 A: Very beautiful question. For the partial proof of the problem we will use 2 lemmas:

$n$ can be written as a sum of $2$ squares if and only if, for every prime $p$ such that $p\equiv 3\pmod{4}$, the exponent of $p$ in $n$ is even. (This is the Two Square Lemma) $(1)$


If a prime $p$, $p\equiv 3\pmod{4}$ divides $a^2+b^2$, then $p$ divides both $a$ and $b$. (This comes directly from quadratic reciprocity) $(2)$

Lets begin the proof:
By $(2)$, if there exists a prime $p$ such that $p\equiv 3\pmod{4}$ and $p|b$, then $p|a^2+(a+1)^2$, so $p|a^2$ and $p|(a+1)^2$. However, $a$ and $a+1$ are relatively prime, so $a^2$ and $(a+1)^2$ are relatively prime, so $p$ cannot divide both $a^2$ and $(a+1)^2$.
So there is no prime $p$such that $p\equiv 3\pmod{4}$ and $p|b$, so by $(1)$, $b$ can indeed be written as a sum of 2 squares.
Let $b=u^2+v^2$. We will assume that $u$ and $v$ are different from $0$. Take $y=\pm v$. To complete the proof, we must show there exist $x,y\in\mathbb{Z}$ such that $bx+(2a+1)y=u$.
To complete the proof, we must only show that $u\equiv \pm(2a+1)v\pmod{b}$.
A: A more general claim is as follows.

Claim. Let $m$ and $n$ be coprime positive integers, and let $b$ be a divisor of $c=m^2+n^2$. Then $b$ can be represented as $b=u^2+v^2$ with $b\mid um-vn $.

Proof. In Gaussian integers, write $c=(m-in)(m+in)$ and $b=(u-iv)(u+iv)$ with $u-iv\mid m+in$ and $u+iv\mid m-in$ (by putting conjugate prime factors of $b$ into corresponding parts). Then $b\mid (u+iv)(m+in)=(um-vn)+i(un+vm)$, so in particular $b\mid um-vn$. $\square$
Now, to answer the question, notice that $b\mid 1^2+(2a+1)^2$ and apply the claim. Then put $y=v$ and $x=(u-(2a+1)v)/b$.
