Problem: Find prime solutions to the equation $p^2+1=q^2+r^2$

I welcome you to post your own solutions as well

I have found a strange solution which I can't understand why it works(or what's the math behind it.) Here it is through examples

Put $r=17$(prime) Now $17^2-1=16\times 18=288=2 \times 144$ (a particular factorization)

$\frac {2+144}{2}=73$

$\frac {144-2}{2}=71$

Solution pair $(p,q,r)=(73,71,17)$

Put $r=23$, $23^2-1=22\times 24=8\times 66$

$\frac {8+66}{2}=37$

$\frac {66-8}{2}=29$

Solution pair $(37,29,23)$

It works for each prime except for $2,3,5$ Which generate $(2,2,1),(3,3,1),5,5,1)$

Please explain me how it's working

  • 4
    $\begingroup$ Voting to reopen. The supposed duplicate says nothing at all about primes. $\endgroup$ – TonyK Jun 7 '20 at 18:50
  • 1
    $\begingroup$ Try it for larger primes. It is not clear whether it still works then. Small numbers are often prime. $\endgroup$ – Peter Jun 7 '20 at 20:38
  • $\begingroup$ @lulu, the OP seems to be asserting that for any prime $r$ (with some small exceptions), you can find primes $p$ and $q$ such that $(p+q)(p-q)=(r-1)(r+1)$. (It makes sense to except $r=2$ and $3$. I don't see why the OP would except $r=5$, though, if indeed that's what they mean.) $\endgroup$ – Barry Cipra Jun 7 '20 at 20:54
  • 2
    $\begingroup$ When you write, Akash, "It works for each prime except for 2,3,5" do you really mean it works for every prime, all the way to infinity? or do you mean, it works for every prime you tried? and, if that's what you mean, how many, or which, primes did you try? $\endgroup$ – Gerry Myerson Jun 8 '20 at 0:31
  • 1
    $\begingroup$ Please, Akash, engage with the comments and answers that have been posted. $\endgroup$ – Gerry Myerson Jun 9 '20 at 13:09

This seems to hold much more broadly than just for primes.

Let$$r^2-1=ab$$where $b>a$, and let $p=\frac{b+a}{2}$ and $q=\frac{b-a}{2}$.

Then the equation $p^2+1=q^2+r^2$ becomes$$\left(\frac{b+a}{2}\right)^2+1=\left(\frac{b-a}{2}\right)^2+ab+1$$and we have$$\frac{b^2+2ab+a^2}{4}+1=\frac{b^2-2ab+a^2+4ab}{4}+1=\frac{b^2+2ab+a^2}{4}+1$$

Addendum: If $r$ is an odd prime, then $p$ and $q$, that is $\frac{b+a}{2}$ and $\frac{b-a}{2}$, can be prime only if both are odd, i.e. only if $b\equiv 2\pmod 4$ and $a\equiv 0\pmod 4$, or vice-versa.

This restricts the number of divisor pairs $a, b$ that need to be considered in determining whether $r^2-1=ab$ for some odd primes $p$ and $q$.

To illustrate, let $r=47$. Then$$r^2-1=ab=2208=2^5\cdot3\cdot23$$Thus the possible $ab$ are $2\cdot 1104$, $6\cdot 368$, and $2^4\cdot 138$.

For $b=1104$, $a=2$, $p=\frac{b+a}{2}=553=7\cdot79$, not prime.

For $b=368$, $a=6$, $p=\frac{b+a}{2}=187=11\cdot17$, not prime.

For $b=138$, $a=2^4$, $p=\frac{b+a}{2}=77=7\cdot11$, not prime.

It seems $47$ is the least prime value of $r>3$ for which$$p^2+1=q^2+r^2$$is true for no primes $p$, $q$.

As @Gerry Myerson shows, $r=193$ is another instance. I've yet to find other primes between these two, but have not looked much beyond $r=97$.


Let $r=193$, a prime. Then $$r^2-1=9313^2-9311^2=3107^2-3101^2=323^2-259^2$$ are the only expressions of $r^2-1$ as a difference of two squares, but $9313=67\times139$, and $3101$ and $259$ are both multiples of $7$. Thus, $p^2+1=q^2+r^2$ is impossible in primes $p,q$ for this prime value of $r$.


The below identity can be utilized to get prime solutions.


$(mp+nq)^2+(mn-pq)^2=(mn+pq)^2+(mp-nq)^2$ ---(1)

Since one of the four elements in equation (1) needs to be equal to one we take:

$(mn-pq)=+1 or -1$

We choose:



And we get: $(a,b,c)=(37,29,23)$

Also for, $(m,n,p,q)=(5,7,9,4)$

We get: $(mn-pq)=(35-36)=(-1)$

And, $(a,b,c)= (73,17,71)$





Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.