As the title says I'm looking for a general solution to a Diophantine equation of the form:

$y^2 = x^2 + kx - m$

Where $x$ and $y$ are both positive integers. I know that $k$ and $m$ will always be a multiple of 2 if that helps.

Here are a few examples that I solved through brute force.

  1. $y^2 = x^2 + 30 x - 28$
    $x = 2$
    $y = 6$

  2. $y^2 = x^2 + 474 x - 554$
    $x = 45$
    $y = 151$

  3. $y^2 = x^2 + 1802 x - 3018$
    $x = 37$
    $y = 255$

I'm a bit of a dummy so a thorough explanation would be much appreciated. Thanks in advance!

  • $\begingroup$ How about you choose any values you want for $x$, $y$, and $k$ and then set $m=x^2 + kx-y^2 $? $\endgroup$ Apr 16, 2018 at 13:20
  • $\begingroup$ Unfortunately not I'm writing an algorithm that returns $y$ given $f(k, m)$ $\endgroup$ Apr 16, 2018 at 15:28
  • $\begingroup$ Then should I volte to close your question because it's unclear what you're asking? $\endgroup$ Apr 16, 2018 at 16:24

2 Answers 2


Hint: Write $k=2b$. Then $y^2 = (x+b)^2 -b^2 - m$ and so $m+b^2=(x+b)^2 -y^2$ is a difference of two squares. Now use this well-known fact, which is easy to prove:

$N \in \mathbb Z$ is a difference of two squares iff $N$ is odd or a multiple of $4$.

To be explicit, if $N=uv$ with $u$ and $v$ of the same parity, then $$ N=uv=\left(\dfrac{u+v}2\right)^2 - \left(\dfrac{u-v}2\right)^2 $$

Therefore, the general solution of $y^2 = x^2 + kx - m$ follows from factoring $N=m+(\frac k2)^2$ as two factors of the same parity and using the formula above to find $x+\frac k2$ and $y$.

Let's see how this works for your first example: $m+b^2=28+15^2=253=11\cdot 23=17^2-6^2$. Therefore, $x+15=17, y=6$. This is the only solution.

  • $\begingroup$ Thank you for the great explanation. But factoring if I'm unlucky is a lot harder than trying different values of $x$ especially since I can trace the squares by summation of odd numbers. I forgot to specify that I'm trying to write an algorithm to solve these. $\endgroup$ Apr 16, 2018 at 15:36

Above equation shown below, has parametric soution:


$(x)= (2w)(p^2-6p+23)$

$(y)= (2w)(3p^2-9p-42)$

$(k)= (30w)(p^2+6p+5)$

$(m)= (28w^2)(p^2+6p+5)(p^2+14)$

Where $w=1/(p^2+14)$

For p=3 we get:

$84^2=28^2 +960(28)-20608$


You must log in to answer this question.

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