Solve $2(x+y)+xy=x^2+y^2$ where $x,y \in \mathbb{Z}$ Solve the equation: $$2(x+y)+xy=x^2+y^2$$
How should I go about solving this? Any guidance appreciated.
Thanks!

$ 2(x+y) + xy = x^2 + y^2 $
$ 2(x+y) + 3xy = (x+y)^2 $
$ u = x + y, v = xy $
$ 2u + 3v = u^2 $
$ u^2 - 2u - 3v = 0 $
$ \frac{1}{2}u^2 - u - \frac{3}{2}v = 0 $
$ D = 1 + 3v $
$ u = 1 + \sqrt{1 + 3v} $ or $ u = 1 - \sqrt{1 + 3v} $
Let $ \sqrt{1+3v} = k $, hence $ v = \frac{k^2 - 1}{3} $
First case $ u = 1 + \sqrt{1+3v} $
$ x + y = 1 + k $
$ xy = \frac{k^2 - 1}{3} $
$ y = 1 + k - x $
$ 3x(1+k-x) = k^2 - 1 $
$ 3x + 3kx - 3x^2 = k^2 - 1 $
$ 3x^2 - 3(k+1)x + k^2 - 1 = 0 $
$ D = 9(k+1)^2 - 12 (k^2 - 1) = -3k^2 + 18k + 21 = -3(k^2 - 6k - 7) = -3(k+1)(k-7) $
$ -3(k+1)(k-7) >= 0 $, hence $ k \in [-1, 7] $ and $ k \in \mathbb N $
$x = \frac{3(k+1) \pm \sqrt{-3(k+1)(k-7)}}{6}$
Because of this $ k $ may be 1, 5 or 7 for $ \sqrt{-3(k+1)(k-7)} \in \mathbb Z $
$ k = 1 $, hence $ x = 2 $ and $ y = 0 $ OR $ x = 0 $ and $ y = 2 $
Similarly you can regard cases $ k = 5 $ and $ k = 7 $ AND $ u = 1 - \sqrt{1 + 3v} $.
In summary the answer will be $ (0, 0) $, $ (0, 2) $, $ (2, 0) $, $ (2, 4) $, $ (4, 2) $, $ (4, 4) $.
