# For what pair of integers $(a,b)$ is $3^a + 7^b$ a perfect square.

Problem: For what pair of positive integers $(a,b)$ is $3^a + 7^b$ a perfect square.

First obviously $(1,0)$ works since $4$ is a perfect square, $(0,0)$ does not work, and $(0,1)$ does not work, so we can exclude cases where $a$ or $b$ are zero for the remainder of this post.

I have a few observations made but not much room for a full solution.

First, since powers of an odd number are odd, and the sum of two odd numbers is even, so the base of the square must be an even number.

Secondly, the last digit of the powers of $3$ are $\{1,3,7,9 \}$ , whereas the last digits of the powers of $7$ are $\{7,9,3,1 \}$.

From here I am not sure how to proceed and any hints much appreciated. I'm not sure if there a finite amount of pairs or not either.

• The only pairs , I found so far , are $(1/0)$ and $(2/1)$ Oct 9, 2017 at 21:44
• Every square is either $0$ or $1$ modulo $4$. We have $$3^a+7^b\equiv(-1)^a+(-1)^b\mod4\ ,$$ therefore we must necessarily have $a$ even and $b$ odd, or the converse. Oct 9, 2017 at 21:46
• Since for $0\le a,b\le 1000$, the only pairs are $(1/0)$ and $(2/1)$, another pair would be a mircale considering how large one of the powers must be. However, proving this could be extremely difficult, but it could also be relatively easy if someone finds a clever trick. Oct 9, 2017 at 22:01
• @VidyanshuMishra PARI/GP is very powerful for such questions! There are surely faster programs, however. Oct 9, 2017 at 22:04
• Ah.. Thanks @Peter, I shall have a look at it. Oct 9, 2017 at 22:04

Here is a solution using less machinery than in Will Jagy's answer.

As Daniel Robert-Nicoud noted in comments, the fact that $3^a+7^b\equiv(-1)^a+(-1)^b$ mod $4$ implies $a$ and $b$ must have opposite parity in order for the (even) sum $3^a+7^b$ to be a perfect square. So we seek to show that $(a,b)=(1,0)$ is the only solution in the (odd,even) case and $(a,b)=(2,1)$ is the only solution in the (even,odd) case.

If $a$ is odd and $b=2m$ is even, then we can rewrite $3^a+7^b=n^2$ as $3^a=(n+7^m)(n-7^m)$. This implies $n+7^m$ and $n-7^m$ are each powers of $3$, say $3^c$ and $3^d$ with $c+d=a$. But then $2\cdot7^m=3^c-3^d$, so we must have $d=0$ and $c=a$, since $3\not\mid2\cdot7^m$. One solution to $2\cdot7^m=3^a-1$ is $(a,m)=(1,0)$. It remains to show there are no solutions with $m\gt0$. For this it suffices to note that $3^a\equiv1$ mod $7$ if and only if $6\mid a$, which contradicts the assumption that $a$ is odd.

In the other parity case, if $a=2m$ is even and $b$ is odd, then, along similar lines, we must have $2\cdot3^m=7^b-1$, which has $(m,b)=(1,1)$ as one solution. After checking that there is no solution with $m=0$, it remains to show there are no solutions with $m\gt1$. If there were, then we would have $7^b\equiv1$ mod $9$, which would imply $b\equiv3$ mod $6$ (since $6$ is the order of the multiplicative group of units mod $9$ and $7^3\equiv(-2)^3=-8\equiv1$ mod $9$). Writing $b=3r$ (with $r$ odd, but that doesn't matter), we note that $(7^3-1)\mid(7^{3r}-1)$, so that $7^3-1=2\cdot3^2\cdot19$ divides $2\cdot3^m$, an obvious contradiction.

• Good. In the various problems I had done previously, often a full divisor, such as $7^{12} - 1,$ had several factors that were not used, and a smaller divisor such as your $7^3 -1$ gave enough, in this case the prime $19.$ I used the prime $43$ out of $7^{12} - 1.$ Lack of practice. Plus, of course, I did not use the full strength of Daniel's comment. Oct 10, 2017 at 17:11
• Wow. That is a fantastic answer much appreciated. Oct 10, 2017 at 19:58
• why does d = 0 and c = a ? Oct 11, 2017 at 4:22
• @IntegrateThis, if $c$ and $d$ are both greater than $0$, then $3\mid(3^c-3^d)$. But $3\not\mid2\cdot7^m$. Oct 11, 2017 at 12:26

Just to register, from the comment by Daniel, there are just two possibilities, if the result is $x^2,$ either $$1 + 2 \cdot 3^c = 7^d,$$ or $$1 + 2 \cdot 7^e = 3^f.$$

I would guess that an elementary method shown in an answer by Gyumin Roh to http://math.stackexchange.com/questions/1551324/exponential-diophantine-equation-7y-2-3x can be modified for this task. My way of working with this takes a while...

http://math.stackexchange.com/questions/1941354/elementary-solution-of-exponential-diophantine-equation-2x-3y-7

http://math.stackexchange.com/questions/2100780/is-2m-1-ever-a-power-of-3-for-m-3/2100847#2100847

• Ok will study those and get back to you. Oct 9, 2017 at 22:17
• @IntegrateThis got one of the two so far, posted as separate answer. Oct 10, 2017 at 0:33
• @IntegrateThis got the final one, third answer. Oct 10, 2017 at 0:57
• @WillJagy, I think I found the elementary alternative. Oct 10, 2017 at 13:27

The technique I mentioned is working. One of the cases is $$1 + 2 \cdot 3^c = 7^d,$$ where we think that $c=d=1$ gives the largest such answer. Subtract $7$ from both sides, $$2 \cdot 3^c - 6 = 7^d - 7.$$ Let $y+1 = c,$ $x+1 = d,$ for $$6 \cdot 3^y - 6 = 7 \left( 7^x -1 \right),$$ $$6 \left( 3^y -1 \right) = 7 \left( 7^x -1 \right).$$ We are assuming $x,y \geq 1,$ with both sides being nonzero.

$$3^y \equiv 1 \pmod 7,$$ $$y \equiv 0 \pmod 6.$$ Next, $3^y - 1$ is divisible by $3^6 - 1 = 728 = 8 \cdot 7 \cdot 13.$

$$7^x \equiv 1 \pmod {13},$$ $$x \equiv 0 \pmod {12}.$$ Next, $7^x - 1$ is divisible by $7^{12} - 1 = 13841287200 = 32 \cdot 9 \cdot 25 \cdot 13 \cdot 19 \cdot 43 \cdot 181.$

$$3^y \equiv 1 \pmod {43},$$ $$y \equiv 0 \pmod {42}.$$ Next, $3^y - 1$ is divisible by $3^{42} - 1 = 109418989131512359208 = 8 \cdot 7^2 \cdot 13 \cdot 43 \cdot 547 \cdot 1093 \cdot 2269 \cdot 368089$

All we care about is that $3^y - 1$ is divisible by $7^2 = 49,$ as this contradicts the assumption of $x \geq 1$ in $$6 \left( 3^y -1 \right) = 7 \left( 7^x -1 \right).$$ $$\bigcirc \bigcirc \bigcirc \bigcirc \bigcirc \bigcirc \bigcirc \bigcirc \bigcirc \bigcirc \bigcirc \bigcirc \bigcirc \bigcirc \bigcirc \bigcirc$$

The other case is $1 + 2 \cdot 7^x = 3^y,$ or $$3^y - 1 = 2 \cdot 7^x.$$ Assume $x \geq 1.$ Then both sides are divisible by $7,$ giving $$3^y \equiv 1 \pmod 7,$$ $$y \equiv 0 \pmod 6.$$ Then $3^y - 1$ is divisible by $$3^6 - 1 = 728 = 8 \cdot 7 \cdot 13.$$ However, then $2 \cdot 7^x$ is divisible by $13,$ which is a contradiction. $$\bigcirc \bigcirc \bigcirc \bigcirc \bigcirc \bigcirc \bigcirc \bigcirc \bigcirc \bigcirc \bigcirc \bigcirc \bigcirc \bigcirc \bigcirc \bigcirc$$