Solve $x^2 – ny – 2 = 0$ for integer solutions, with different coefficients of $y$

diophantine equationspolynomialsquadratic-formsquadraticssystems of equations

$$x^2 – ny – 2 = 0, n \in Z$$

I put this equation in wolframalpha, and got integer solutions for random n = 7, 23, 31, 47, 49, 71, 73, 343.

for n = 7 it gave the integer solutions as $$x = 7 n + 3, y = 7 n^2 + 6 n + 1, n \in Z$$
$$x = 7 n + 4, y = 7 n^2 + 8 n + 2, n \in Z$$

and for n = 23 it gave the integer solutions as $$x = 23 n + 5, y = 23 n^2 + 10 n + 1, n \in Z $$
$$x = 23 n + 18, y = 23 n^2 + 36 n + 14, n \in Z $$

It was noteworthy that the sum of free numbers in x is always equal to n (i.e. coefficient of y). 7 had 3 and 4 as free-x-values, 23 had 5 and 18 as free-x-values, and so on. So, as we can see, those free-x-values are always smaller than n.

For some values (like even numbers) there weren't any solutions shown, So I guess there weren't any. But as most of these have only 2 integer solutions, some had 4 integer solutions, like 511 for an example, which had 2 pairs of free-x-values, adding to 511.

My question is, how do I determine if the equation has only exactly 2 solutions, or more than 2 solutions, for a given value of n (i.e. coefficient of y)?

I'm not particularly concerned with the solutions themselves, just that the number of solutions is just 2 or more than that. I can't try values one by one, as the coefficient of y can get large. Wolfram isn't (understandably) handling that big numbers, so I'm trying to write code to solve these equations, but as I don't know what is going on behind the scenes, I can't do anything.

Also, let's say if I find the 1st (smallest) solution, and the 4th (as their sum is predetermined). Can I use them to find the other two (2nd and 3rd) solutions, if they exist?

I looked into Diophantine equations of degree two, but the examples I found had all variables of second degree in them. So, I'm not sure if it qualifies for that. If if still does, please let me know.
I tried to solve the equation as a quadratic equation, but got stumped as the coefficient of $y^2$ is 0.

My mathematical background is only upto basic highschool level. So, if I need to study some field(s), to be able to solve this, please guide me, as I'm willing to study to solve this problem.

Best Answer

Well, if you would have $n|x^2-2$, then putting $y = \frac{x^2-2}{2}$ gives us a legitimate solution. So we only need to be worried about solutions to that divisibility.

You can easily see, that if $x$ is a solution, then $n-x$ and $n+x$ are also solutions. That yields your observation with summing up to $n$.

Now we will focus on the set $S$ of such $n$, that some solution exists.

If $k$ and $l$ are coprime numbers in $S$, then using Chinese Remainder Theorem we can find solution for $kl$. Moreover, the number of solutions for $kl$ will be equal to the product of these numbers for $k$ and $l$. We also see quite obviously that if $n \in S$, then all divisors of $n$ are in $S$.

From these two facts, we only need to be worried about $n$ equal to prime powers. It is not very easy to prove that $n=p^k$ works iff $n=2$ or $p \equiv 1,7 \pmod 8$, but you should be able to find proof of this fact in any materials about quadratic residues (here, for example, $2$ is a quadratic residue mod $n$, since $x^2 \equiv 2 \pmod n$).

So, solutions exist for $n$ iff all of its prime divisors are $2$ or primes $\equiv 1$ or $7 \pmod 8$, where $2$ can show up only once (so $n$ can't be divisible by $4$, but it can be even). Number of these solutions (or, to be exact, number of different families of sulutions modulo $n$) is equal to $2^k$, where $k$ is number of distinct odd prime divisors of $n$.