Given a number $X$ , we need to find a number $Y$ such that $X+Y$ can be expressed as sum of two squares (say $a^2+b^2$).

It can be observed that number of $Y$ are infinite (and can be generated by plugging value of a and b in $a²+b²-X$).

But, how can we find $Y$ for given number $X$ so X+Y² can be expressed as sum of two squares?

Edit : for example if $X=32$ is given, than $Y$ can be $3$ such that $32 + 3² = 41$ and $41$ can be split into sum of squares of $4$ and $5$ ($4² + 5² = 41$).

  • 1
    $\begingroup$ $y = 0$ should do for the vast majority of cases (Wikipedia). $\endgroup$
    – Toby Mak
    Jun 1, 2020 at 6:29
  • $\begingroup$ But $X$ may not satisfies $X+Y² =a²+b²$ if $Y=0$ ( for example when $X$ is given 7 or 12) $\endgroup$
    – adish jain
    Jun 1, 2020 at 7:14
  • $\begingroup$ If $X+Y^2=a^2+b^2$, then $X-a^2=(b+Y)(b-Y)$. Hence you can factorise $X-a^2$ and solve for $Y$. $\endgroup$
    – Ningxin
    Jun 1, 2020 at 7:37
  • $\begingroup$ Can't we just get $Y=a^2+b^2-X$ for $a>b>X$? $\endgroup$ Jun 1, 2020 at 8:24

2 Answers 2


Choose an $a$ so that $X-a^2$ is odd: $$X-a^2=2Y+1=(Y+1)^2-Y^2,$$and that implies $$X+Y^2=a^2+(Y+1)^2.$$


If $X$ is even number, we can get a solution below.
Hence $Y=a-b, X=2ab$.


You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .