# $a+n^2$ is the sum of two perfect squares

$$a+n^2$$ is the sum of two perfect squares for a given positive integer $$a$$ and all positive integers $$n$$. Show that $$a$$ is a perfect square.

At first I thought of putting a bound on the difference between perfect squares up to a point, like maybe choosing $$n=c$$ so that one of the squares on the right hand side is the smallest, to try and show that if $$a = x^2 + k< (x+1)^2$$ that there would have to be two pairs of squares with the same difference, but I can't seem to work out the details

• What is the meaning of "all positive integers n"?
– Moti
Feb 5, 2021 at 4:50
• @Moti exactly as it says, it satisfies the conditions for $n=1,2,3,...$ and so on Feb 5, 2021 at 5:45
• Since $a+1$ and $a+a^2$ can both be written as the sum of two perfect squares, and $(a+a^2)/(a+1) = a$, it easily follows from the Sum of Two Squares Theorem that $a$ can also be written as the sum of two squares. I'm not sure if that can be used to show that $a$ itself is a perfect square, but I'll leave it here just in case it helps someone else solve this problem. Feb 5, 2021 at 6:42
• See quora.com/…. Feb 5, 2021 at 8:23

The general solution of the equation $$x^2+y^2=z^2+w^2$$ is given by the identity with four arbitrary parameters $$(tX+sY)^2+(tY-sX)^2=(tX-sY)^2+(tY+sX)^2$$ Let $$n$$ be any integer so we have $$a+n^2=z^2+w^2$$Making $$n=tY-sX\\z=tX-sY\\w=tY+sX$$ we have three equations with four unknowns which in general have infinitely many solutions. Any way we have $$n^2=t^2Y^2+s^2X^2-2stXY\\z^2=t^2X^2+s^2Y^2-2stXY\\w^2=t^2Y^2+s^2X^2+2stXY$$ which implies $$z^2+w^2-n^2=t^2X^2+s^2Y^2+2stXY=(tX+sY)^2$$ Since $$a=z^2+w^2-n^2$$ we have $$a=(tX+sY)^2$$ We are done.