Determine all pairs $(a, n)$ of positive integers such that

$$
3^{n}=a^{2}-16
$$
Let $(a, n)$ be a solution to the equation.

Then, $3^{n}=(a-4)(a+4)$.

We deduce that $a-4$ and $a+4$ are powers of 3.

There exist integers $k$ and $l$ such that $a-4=3^{k}$ and $a+4=3^{l}$ (with $l \geqslant k$).

Thus, $8=(a+4)-(a-4)=3^{k}\left(3^{l-k}-1\right)$.

Since 3 does not divide 8, we get $k=0$ and $8=3^{l}-1$ hence $l=2$. Therefore, $a-4=1$ so $a=5$ and $n=2$. Conversely, the pair $(5,2)$ is a solution to the required equation.