System of two equations with three integer unknowns

Hi all,

here is my problem. I have the following system :

$\displaystyle S \left\{\begin{array}{cc}a^2 - ab + n = 0

\\a^2 - ac - n = 0\end{array}\right.$

Where $\displaystyle a$, $\displaystyle b$ and $\displaystyle c$ are *integer* unknowns and $\displaystyle n$ is any integer value (known)

Is there any *general* way to solve such equations quickly (for all three unknowns) ? Thanks a lot !

Brute Force Approach - General

Solve for a using the quadratic formula: $\displaystyle 2a=b\pm\sqrt{b^2-4n}=c\pm\sqrt{c^2+4n}$

Now isolate b in terms of c: $\displaystyle b^2-4n=(c-b\pm\sqrt{c^2+4n})^2$

Solution: $\displaystyle b=\frac{c^2\pm c\sqrt{c^2+4n}+4n}{c\pm\sqrt{c^2+4n}}$

Simplify by multiplying by the conjugate: $\displaystyle b=\pm\sqrt{c^2+4n}$, or equivalently, $\displaystyle c=\pm\sqrt{b^2-4n}$

Substituting, $\displaystyle 2a=b+c$

A better way of expressing the solution is by finding b,c such that $\displaystyle b^2-c^2=4n$, and let $\displaystyle a=\frac12(b+c)$

For a to be an integer, $\displaystyle b+c$ must be even, so b,c must have the same parity (both even or both odd), so $\displaystyle b-c$ is even also.

An all-integer answer can thus be gotten: Given n, factor n, and find b,c satisfying $\displaystyle b^2-c^2=4n$, or $\displaystyle \frac{b+c}{2}\frac{b-c}{2}=n$. Define a as above.

This solution has the advantage of working for all $\displaystyle n\in\mathbb{Z}$ -- there are no restraints on n. Given a random n, the number of a,b,c solutions is equivalent to the number of unique ways to factor $\displaystyle n=xy$, WLOG $\displaystyle x\geq y$

Interestingly, a|n necessarily, so dividing through both equations by a, we arrive at the solution:

Given any integer n, choose a factor of n, a|n, and define b=a+n/a, c=a-n/a. We might have guessed at this solution from the start, but the preceding serves as a formal proof that it is the whole and only solution (aside from the trivial a=b=c=0, which works iff n=0).