# Solving quadratic diophantine equations in two variables

I've looked at the recommended questions, but none of them seem to match my question.

Consider the equation $2015 = \frac{(x+y)(x+y-1)}{2} - y + 1$.

This can trivially be simplified to $4030 = x^2 + 2xy - x + y^2 - 3y +2$.

According to Wolfram Alpha, the integer solutions of this equation can be represented as:

$x = -\frac{n^2}{2} + \frac{5n}{2} + 2012,\:y = \frac{n^2}{2} - \frac{3n}{2} - 2013,\:n \in \mathbb{Z}$.

Can someone explain how this set of solutions is derived?

The equation is $$x^2 + 2xy + y^2 - x -3y - 4028 = 0.$$

This can be modified to

$$(x+y)^2 - (x+y) - (2y+4028) = 0.$$

Let's denote $u = x+y$ so we have

$$u^2 - u = 2(y+2014)$$

Solving for $y$, we have

$$y = \frac{u^2-u}{2}-2014.$$

Then, remembering that $u=x+y$, we can solve for $x$:

$$x = u-y = u-\frac{u^2-u}{2}+2014 = \frac{-u^2+3u}{2}+2014.$$

Then we set $n=u-1$ (just a shift (to make the solution look the same)) and get the solution

$$x = \frac{-n^2+5n}{2}+2012$$ $$y = \frac{n^2-3n}{2}-2013$$