Find all integers $a \geq 1$ such that the integer $1-8 \cdot 3^{a}+2^{a+2}\left(2^{a}-1\right)$ is a perfect square.
The quantity $1-8 \cdot 3^{a}+2^{a+2}\left(2^{a}-1\right)$ is equal to $\left(2^{a+1}-1\right)^{2}-2^{3} \cdot 3^{a}$. We notice that it is a square for $a=3$ (it equals $9=3^{2}$) and $a=5$ (it equals $2045=25^{2}$) but not for $a \in\{1,2,4,6,7,8\}$. We now assume $a \geq 9$.

Suppose that $1-8 \cdot 3^{a}+2^{a+2}\left(2^{a}-1\right)$ is a square, that is, since this quantity is odd, there exists an odd integer $k$ such that

$$
\left(2^{a+1}-1\right)^{2}-2^{3} \cdot 3^{a}=(2 k+1)^{2}
$$

Thus

$$
\left(2^{a+1}-1\right)^{2}-(2 k+1)^{2}=2^{3} \cdot 3^{a}
$$

or equivalently $\left(2^{a}-k-1\right)\left(2^{a}+k\right)=2 \cdot 3^{a}$. There then exists an integer $b \geq 0$ such that one of the following two situations occurs (depending on the parity of $k$):

Case 1. We have $2^{a}+k=2 \cdot 3^{b}$ and $2^{a}-k-1=3^{a-b}$.

Case 2. We have $2^{a}+k=3^{b}$ and $2^{a}-k-1=2 \cdot 3^{a-b}$.

First, let's consider Case 1. We have $2 k+1=2 \cdot 3^{b}-3^{a-b}$, and thus $b \geq a-b$. Moreover, $2^{a+1}-1=3^{a-b}+2 \cdot 3^{b}$. Therefore,

$$
2^{a+1}-1=3^{a-b}\left(1+2 \cdot 3^{2 b-a}\right)
$$

Since $a \geq 9$, we have $a-b \geq 3$, so $3^{3}$ divides $2^{a+1}-1$. The order of 2 modulo $3^{3}$ is 18. Therefore, $a \equiv 17 \bmod 18$. It is natural to consider the equation modulo 19 because then $2^{a+1}$ is constant modulo 19 and equals 1 (alternatively, $19\left|2^{18}-1\right| 2^{a+1}-1$). Therefore,

$$
\left(2^{a+1}-1\right)^{2}-2^{3} \cdot 3^{a} \equiv(1-1)^{2}-2^{3} \cdot 13 \equiv 10 \quad \bmod 19
$$

Then, by (III.1), $(2 k+1)^{18} \equiv 10^{9}=18 \bmod 19$, which contradicts Fermat's Little Theorem.

Now, let's consider Case 2. We have $2 k+1=3^{b}-2 \cdot 3^{a-b}$, and thus $b \geq a-b$. Moreover, $2^{a+1}-1=3^{b}+2 \cdot 3^{a-b}$. Therefore,

$$
2^{a+1}-1=3^{a-b}\left(3^{2 b-a}+2\right)
$$

and we conclude as in the first case.

Therefore, there are no solutions for $a \geq 9$. In conclusion, the only solutions are 3 and 5.