I have this equation with 2 variables –
$$x^2 – y^2 -2xy – x + y = 0$$
The only condition I have is that $x + y$ should be greater than $10^{12}$.
EDIT – I need $x$ and $y$ to be integer.
I generally use binary-search to solve quadratic equation, but in this equation I realized that binary-search can't work.
Here is how I tried to solve it (which is wrong) –
1. Set sum
to $10^{12}$
2. Set some value for $x$
3. Do binary-search to find if some value of $x$ & $y$ satisfy function. <- WRONG
Please suggest some way to solve this equation.
Best Answer
You can solve for $x$ in terms of $y$ as follows. Add and subtract $y^2$:
$$x^2-2 x y + y^2 - x + y - 2 y^2 = 0$$
which may be further rewritten as
$$(x-y)^2-(x-y) - 2 y^2 = 0$$
This is a quadratic in $x-y$; solve to get
$$x-y = \frac{1\pm\sqrt{1+8 y^2}}{2} $$
or
$$x = y + \frac{1\pm\sqrt{1+8 y^2}}{2} $$