# Solving a quadratic Diophantine equation

I want to solve the following quadratic Diophantine equation:

$$\frac{x(x-1)}{y(y-1)}=\frac{p}{q} \hspace{5 mm}, \hspace{5 mm}p\le q$$ For $p=1$ and $q=2$, it is easy to solve.

Let $y=x+z$. Then after some simplification we get

$x^2-(2z+1)x-(z^2-z)=0$

For integral solution, the discriminant of this equation must be a whole square. Hence

$8z^2+1=k^2$

Now it is a standard Pell's equation which can easily be solved. But for arbitrary $p$ and $q$, using similar approach I get

$(2pz+q-p)^2+4p(q-p)(z^2-z)=k^2$

I am stuck here. Can someone help me?

• It is still a quadratic in $z$, and the earlier approach should work for any specific $p,q$. If you are looking for a general expression for the solutions in terms of $p,q$ I doubt you'll get it though. – Macavity Aug 30 '15 at 15:01
• In earlier case I managed to get the standard Pell's equation of form $x^2-dy^2=1$. How can I approach for any $p$ and $q$. Yes, closed form is not possible in terms of $p$ and $q$, but there might be some other method. – guest123456 Aug 30 '15 at 15:09
• You may want to take a look at math.stackexchange.com/questions/490617/… – Macavity Aug 30 '15 at 15:58
• @guest123456: Actually, a closed-form is possible. – Tito Piezas III Aug 31 '15 at 4:45

Here's a broad solution in integers. Given,

$$\frac{x(x-1)}{y(y-1)}=\frac{p}{q}\tag1$$

All you do is directly solve $(1)$ as a quadratic in $x$ and make its discriminant a square. After some manipulation, I find,

$$x = pv(u+qv)$$

$$y = qv(u+pv)$$

and $u,v$ solve,

$$u^2-pqv^2 = \color{red}-1\tag2$$

Or,

$$x = pv(u+qv)+1$$

$$y = qv(u+pv)+1$$

and $u,v$ solve,

$$u^2-pqv^2 = 1\tag3$$

• It seems that you missed $+1$ at the end of both the expression of $x$ and $y$. – guest123456 Aug 31 '15 at 13:14
• @guest123456: Oh, you're right. The first solution is for the negative Pell equation. I've edited, and also got rid of the unnecessary factor of 2. Thanks. :) – Tito Piezas III Aug 31 '15 at 13:36
• Your method does not give the complete set of solutions. For example if $p=1$ and $q=2$, then your method gives $x=15$ and $y=21$, which is correct but not the smallest solution. Smallest solution is $x=3$ and $y=4$. – guest123456 Aug 31 '15 at 13:50
• @guest123456: Yes, I know. That's why I carefully started with "Here's a broad..." Nowhere in your post did you ask for the complete solution. :) – Tito Piezas III Aug 31 '15 at 13:58
• @guest123456: Using the negative Pell, it does give the smallest solution. Let $p,q=1,2$, and $u^2-2v^2 =-1$, so $u,v = 1,1$, and the formula yields $x,y = 3,4$. – Tito Piezas III Aug 31 '15 at 14:12

I stopped at,

$$(2pz+q-p)^2+4p(q-p)(z^2-z)=k^2\tag1$$

After further simplification,

$$4pqz^2+(q-p)^2=k^2\tag2$$

then,

$$\big(\frac{k}{q-p}\big)^2-\frac{4pq}{(q-p)^2}z^2=1\tag3$$

which is the standard Pell's equation. Now it can easily be solved.

• How did you get from $(2)$ to $(3)$? – Tito Piezas III Aug 31 '15 at 11:31
• Thanks for pointing out the mistake. – guest123456 Aug 31 '15 at 12:58