Find all strictly positive integers $a$ and $n$ such that

$$
3^{n}+1=a^{2}
$$
Let $a, n \geqslant 1$ be integers such that $3^{n}+1=a^{2}$. Since we know how to factorize a difference of squares, write $3^{n}=(a-1)(a+1)$. The integer 3 being prime, $a-1$ and $a+1$ are both a power of 3. Therefore, there exist two integers $b, c \geqslant 0$ such that $a-1=3^{b}$ and $a+1=3^{c}$ (with $b+c=n$ and $c>b$). Then $3^{b}+2=3^{c}$, and thus $2=3^{c}-3^{b}$. If $b>0$, the right-hand side of the equation is divisible by 3, and therefore 3 must divide 2, which is absurd. Therefore, $b=0$, and $2=3^{c}-1$ and thus $c=1$. Hence $a=2$ and $n=1$, and we verify conversely that this solution works.