1

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.

vesszabo
  • 3,481

4 Answers4

8

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} $$

Ron Gordon
  • 138,521
2

Try letting $x+y=u$ and $x-y=v$, so that $x=(u+v)/2$ and $y=(u-v)/2$. Modifying slightly the first part of Ron Gordon's answer, the equation $x^2-y^2-2xy-x+y=0$ can be rewritten as $2(x-y)^2-2(x-y)-(2y)^2=0$, which can be expressed as

$$2v^2-2v-(u-v)^2=0$$

or

$$v^2+2(u-1)v-u^2=0$$

for which one has

$$v=(1-u)\pm\sqrt{(u-1)^2+u^2}\qquad(*)$$

From here, you can plug in any value for $u$ greater than the stipulated $10^{12}$, solve for $v$, and then use the formulas $x=(u+v)/2$ and $y=(u-v)/2$ to get values for $x$ and $y$.

Ah, I see the OP has added the request that $x$ and $y$ be integers. This requires $u$ and $v$ to also be integers, of the same parity. It's easy to see that the parity condition is satisfied by any solution of $(*)$. Thus it's only necessary to find a large integer $u$ such that $(u-1)^2+u^2=k^2$ for some integer $k$. But this can be written as

$$U^2-2k^2=-1$$

where $U=2u-1$. This is a case of Pell's equation: take the "fundamental solution" $1+\sqrt2$, raise it to a sufficiently high (odd) power $(1+\sqrt2)^n$, expand that out with the binomial theorem, collect terms until you got something of the form $U+\sqrt2k$, and there you go.

A somewhat quicker way to get $a$ solution is to use a recursion based on repeated squarings:

$$(1,1)\to(3,2)\to(17,12)\to\ldots\to(U_n,k_n)\to(U_n^2+2k_n^2,2U_nk_n)\to\ldots$$ (followed by one more multiplication to get to an odd power).

Added later: With a little help from Wolfram Alpha, I get $x=756{,}872{,}327{,}473$ and $y=313{,}506{,}783{,}024$ as a solution with the smallest sum greater than $10^{12}$.

Barry Cipra
  • 79,832
0

Adding on to Ron Gordon's solution, here's how you find integer $y$ values that give integer $x$:

$\displaystyle (1+8y^2)$ has to be a square, and since it's odd, you can say $8y^2 +1 = (2k+1)^2$ and hence $\displaystyle y^2 = \frac{k(k+1)}{2}$.

That means that $y^2$ has to be a square triangular number. These are given explicitly by Euler's formula as per this wiki: http://en.wikipedia.org/wiki/Square_triangular_number

So $y$ has to be a square root of that expression, i.e. $\displaystyle y = \frac{(3+2\sqrt{2})^n - (3-2\sqrt{2})^n}{4\sqrt{2}}$, where $n$ is an integer.

Deepak
  • 26,801
0

For the equation: $x^2-y^2-2xy-x+y=0$

Solutions can be written using the solutions of Pell's equation: $p^2-2s^2=\pm1$

And the solutions are of the form:

$x=\pm{p(p+s)}$

$y=\pm{ps}$

Main characters are not confused and consider that there can be a number of different characters themselves.

Solutions can be found knowing the previous. According to the formula.

$p_2=3p+4s$

$s_2=2p+3s$

if we need solutions $+1$ then $(p,s)=(3,2)$

if we need solutions $-1$ then $(p,s)=(1,1)$

Cookie
  • 13,532
individ
  • 4,301