# If $p$, $q$ are naturals, solve $p^3-q^5=(p+q)^2$.

In If $p,q$ are prime, solve $p^3-q^5=(p+q)^2$., the author asks to solve the equation $p^3-q^5=(p+q)^2$ for primes $p$ and $q$. A proof is given that $p=7, q=3$ is the only solution.

In this "followup", I would like to ask for a proof that does not depend on $p$ and $q$ being primes but allows arbitrary positive integers.

I do have an elementary proof for the case in which $p$ and $q$ are relatively prime, but the case in which they aren't is giving me a hard time. Anyone here who can help?

9/12 update: As I commented, I may have been wrong when I claimed I had a proof for the case where $p$ and $q$ are relatively prime, but it should be possible to prove with the additional condition $(p,q+1)=1$ (not $q-1$ as I had written in the comment). Here's the proof:

Assume that $p$ and $q$ are positive integers such that $$p^3-q^5=(p+q)^2\text{,}\tag{1}$$ $$(p,q)=1,\tag{2}$$ $$(p,q+1)=1.\tag{3}$$ Note that (1) implies that $$q<p.\tag{4}$$ Evaluating (1) modulo $q$ gives $p^3\equiv p^2\pmod{q}$, so by (2), $p\equiv1\pmod{q}$, i.e. there exists $a\in\mathbb{N}$ such that $$p=aq+1.\tag{5}$$ Likewise, if we evaluate (1) modulo $p$, we get $-q^5\equiv q^2\pmod{p}$, so $p$ divides $q^5+q^2=q^2(q+1)(q^2-q+1)$ and thus by (2) and (3), $$p\;|\;q^2-q+1.\tag{6}$$ Combining (5) and (6), we get that $p$ divides $q^2-q+1-aq-1=q(q-a-1)$ and therefore by (2), $$p\;|\;q-a-1\tag{7}.$$ Note that, since the right-hand side in (6) is positive, $q-a-1$ must not be negative. On the other hand, (4) implies that it cannot be positive either, so it is $0$ and we have $a=q-1$ and therefore $$p=q^2-q+1.\tag{8}$$ Now, substituting (8) in (1) and evaluating modulo $q^2$ gives $-3q+1\equiv1\pmod{q^2}$, i.e. $q^2$ divides $3q$ which forces $q=3$ and $p=7$.

• Show your proof of the relatively prime case — that way, we can see if it can be adapted (or maybe is even sufficient) for the general case. Sep 9 '14 at 0:47
• @KierenMacMillan: Too bad it's been such a long time since I posted this - my notes from last January are lost now. I have tried to reconstruct the proof but all I managed to come up with is an even weaker result (with the additional property that not only $p$ and $q$ are coprime, but $p$ and $q-1$ as well). This leaves two alternatives: Either I did have a correct proof of my original statement eight months ago and just haven't been able to reconstruct it, or what I had in mind back then was faulty and I didn't notice it. Either way; I'll post what I managed to come up with here. Sep 11 '14 at 19:47
• Equation (3) should read $(p,q+1)=1$. Sep 12 '14 at 12:15
• @rogerl: Of course your're right - I edited it. Thanx Sep 12 '14 at 12:28
• A brute force search gives no solutions for $p\leqslant10^6$. Sep 15 '14 at 10:36

I came up with a solution for $\gcd(p, q)=1$. Note that $p>q$. Looking mod $p$ gives $q^2(q^3+1) \equiv 0 \pmod p$, thus $p|q^3+1$. Take modulo $q$ of both sides of the equation to get $p^2(p-1) \equiv 0 \pmod q$, hence $q|p-1$. So we have $p=qr+1$ for some positive integer $r$. It follows that$$p|q^3+1-p=q^3-qr=q(q^2-r)$$Hence there is some non-negative integer $s$ for which $q^2-r=sp=s(qr+1)$ and consequently$$q^2-rsq-(r+s)=0$$In order to get integer values for $q$ discriminant of this quadratic must be a perfect square, but notice that if $r>1$ and $s>1$ $$(rs)^2<r^2s^2+4(r+s)<(rs+2)^2$$and we must have $r^2s^2+4(r+s)=(rs+1)^2$, which leads to$$r=\frac{4s-1}{2s-4},$$Which is never an integer. Contradiction. Therefore, we must have $r =1$ or $s \le1$.

$r=1$ gives $p=q+1$ and equation becomes $(q+1)^3-q^5=(2q+1)^2$. One can simplify this and get $-q^4+q^2-q-1=0$, so $q|1$ and $q=1$, which fails to satisfy equation.

$s=0$ gives $p=q^3+1$ and equation becomes $(q^3+1)^3-q^5=(q^3+q+1)^2$. So $q$ divides the constant term of polynomial equation, that is $q|2$, and $q=1, 2$, which again fail to satisfy equation.

$s=1$ gives $p=q^2-q+1$ and equation becomes $(q^2-q+1)^3-q^5=(q^2+1)^2$. So $q$ divides the constant term of polynomial equation, that is $q|3$, and $q=1, 3$. $q=1$ fails to satisfy equation. $q=3$ satisfies the equation and gives $p=7$. Therefore $(p, q)=(7, 3)$ is the only solution when $\gcd(p, q)=1$.

• Wow, I'm impressed! Turning the (quite asymmetric) original equation into a highly symmetric quadratic equation is a true piece of art, well done! Jun 24 '16 at 6:25
• Are you sure?? It's such a nice one! Mar 8 '17 at 14:00
• No, I brought it back. Thanks. May 25 '17 at 6:34

Explanatory note: Credit for this answer should really go to user Ghartal who posted it a couple of months ago but decided to withdraw it. Since I found his answer to be extremely nice, I'd be disappointed if it got lost - this is why I am re-posting it here.

I came up with a solution for $\gcd(p, q)=1$. Note that $p>q$. Looking mod $p$ gives $q^2(q^3+1) \equiv 0 \pmod p$, thus $p|q^3+1$. Take modulo $q$ of both sides of the equation to get $p^2(p-1) \equiv 0 \pmod q$, hence $q|p-1$. So we have $p=qr+1$ for some positive integer $r$. It follows that$$p|q^3+1-p=q^3-qr=q(q^2-r)$$Hence there is some non-negative integer $s$ for which $q^2-r=sp=s(qr+1)$ and consequently$$q^2-rsq-(r+s)=0$$In order to get integer values for $q$ discriminant of this quadratic must be a perfect square, but notice that if $r>1$ and $s>1$ $$(rs)^2<r^2s^2+4(r+s)<(rs+2)^2$$and we must have $r^2s^2+4(r+s)=(rs+1)^2$, which leads to$$r=\frac{4s-1}{2s-4}$$A contradiction, since an even number never divides an odd number. Therefore, we must have $r =1$ or $s \le1$.

$r=1$ gives $p=q+1$ and equation becomes $(q+1)^3-q^5=(2q+1)^2$. One can simplify this and get $-q^4+q^2-q-1=0$, so $q|1$ and $q=1$, which fails to satisfy equation.

$s=0$ gives $p=q^3+1$ and equation becomes $(q^3+1)^3-q^5=(q^3+q+1)^2$. So $q$ divides the constant term of polynomial equation, that is $q|2$, and $q=1, 2$, which again fail to satisfy equation.

$s=1$ gives $p=q^2-q+1$ and equation becomes $(q^2-q+1)^3-q^5=(q^2+1)^2$. So $q$ divides the constant term of polynomial equation, that is $q|3$, and $q=1, 3$. $q=1$ fails to satisfy equation. $q=3$ satisfies the equation and gives $p=7$. Therefore $(p, q)=(7, 3)$ is the only solution when $\gcd(p, q)=1$.