Find all natural numbers $x,y$ such that $3^x=2y^2+1$.

There are no solutions other than the three that Satvik Mashkaria exhibited.

This is proved in the paper

Jungmin Ahn, Hyun Kwang Kim, Jung Soo Kim, and Mina Kim: Classification of perfect linear codes with crown poset structure, Discrete Math. 268 (2003), 21-30.

See Lemma 3 of "2.2 The ternary case", pages 26-29.

The proof of Ahn, Kim, Kim, and Kim starts by factoring $2y^2+1$ over the ring ${\bf Z}[\sqrt{2}]$ (as suggested in a comment by user236182), and then uses Skolem's $p$-adic method (with $p=2$); thus their proof is basically elementary, but not easy. The existence of several $(x,y)$, including the large-ish $(5,11)$, suggests that there might not be a really simple proof that no further solutions exist.

[added later: It turns out that in this case Skolem's method is not necessary: it's enough to solve one Pell equation and do a bunch of arithmetic modulo $27$ and either $17$ or $19$. This yields a proof of only half a page or so, instead of the 3-page proof of Ahn et al.; see my second answer to this question.]

This Diophantine equation arises naturally in coding theory. The existence of $x$ such that $3^x = 2y^2+1$ is a necessary condition for the existence of a perfect 2-error-correcting ternary code; the solutions with $y=1$ and $y=2$ correspond to trivial (one-word) codes, and the $y=11$ solution corresponds to the ternary Golay code.


Rewrite as $$3^x-1=2y^2$$ $$(3-1)(1+3+\cdots+3^{x-1})=2y^2$$ $$y^2=1+3+\cdots+3^{x-1}$$ So... perfect squares that are sums of consecutive powers of 3. In other words, perfect squares that in base-3 system write as all ones, and we can seek for $y$ written in ternary $y=(\ldots y_2y_1y_0)_3$. This can then be understood as applying the digit-by-digit square root algorithm in base-3 on all-ones numbers. The algorithm adds two digits to the radicand for each new digit of the result, so there are essentially two paths of calculation: even and odd number of ones. We get to a solution each time the algorithm terminates without residue at the desired number of digits.

Solutions are $\sqrt{(1)_3}=(1)_3$, $\sqrt{(11111)_3}=(102)_3$ and $\sqrt{(11)_3}=(2)_3$. For even-digit and odd-digit, these are truncations of $\sqrt{3/2}=\sqrt{(1.111\cdots)_3}=(1.02000121112\cdots)_3$ and $\sqrt{9/2}=\sqrt{(11.111\cdots)_3}=(2.0100211\cdots)_3$.

I really think there's a more elegant solution, but this one feels interesting because it looks at the problem differently. I'm not sure how to prove that after a while the algorithm never terminates again. Hopefully, one of you will comment to point out something obvious here.


There is a "standard" way to attack this using Thue's theorem, by writing the left hand side as $z^3$, $3 z^3$, or $9 z^3$, depending on the assumed residue $x \pmod 3$. I can't imagine doing a search up to any of the effective versions of Thue's bound on the size of the solutions during an Olympiad.

Some of the comments are close to suggesting that we attack this as a Pell equation, so I have started that below. I don't know how to finish either case. Perhaps one of the commenters would be willing to edit in a completion to either case below.

If $x$ is even, $x = 2k$, this is the Pell equation $(3^k)^2 - 2 y^2 = 1$. The usual technique for finding the minimal solution, constructing convergents of the continued fraction for $\sqrt{2}$, gives the integer solutions $$\begin{align} 3^k &= \frac{1}{2} \left( (3-2\sqrt{2})^n + (3+2\sqrt{2})^n \right) \\ y &= \frac{-1}{2\sqrt{2}} \left( (3-2\sqrt{2})^n - (3+2\sqrt{2})^n \right), \end{align}$$ for any integer $n$ (and not yet applying the restriction that $k$ be a positive integer). Note that $y>0$ requires $n \geq 0$. In fact, $n=0$ gives $3^k = 1$, so $k$ and $x$ are both zero (and $x = 0$ is not allowed). Hence, $n > 0$.

If $x$ is odd, $x = 2k+1$, we multiply through by $3$ to get $3^2 (3^k)^2 - 6 y^2 = 3$, another Pell equation, whose integer solutions are $$\begin{align} 3 \cdot 3^k &= \frac{1}{2}\left( (3+\sqrt{6}) (5-2\sqrt{6})^n + (3 - \sqrt{6})(5+2\sqrt{6})^n \right) \\ y &= \frac{-1}{4} \left( (2+\sqrt{6})(5-2\sqrt{6})^n + (2 - \sqrt{6})(5+2\sqrt{6})^n\right), \end{align}$$ for any integer $n$ (and not yet applying the restriction that $k$ be a positive integer). Note that $y>0$ requires $n>0$.

It's not clear to me that the $k \in \Bbb{N}$ restriction is straightforward to apply to either of these. But I would be happy for someone(s) to edit in a completion to either of the above.