Question: Find all positive integers $n$ such that $$n^2\mid 2^n+1$$
My solution:
Lemma (Lifting the exponent): Let $v_p(n)$ denote the highest power of a prime $p$ that divides $n$.
That is, $v_p(n)=k$ such that $p^k \mid n$ and $p^{k+1} \nmid n$ . We have the following relation: $$\large v_p(x^n-y^n) = v_p(x-y)+v_p(n)$$ for any odd prime $p$ and , $$\large v_2(x^n-y^n)=v_2(x-y)+v_2(x+y)+v_2(n)-1$$ If $n$ is odd then replacing $y$ by $-y$ we obtain $$ \large v_p(x^n+y^n)=v_p(x+y)+v_p(n)$$
The original problem: It is easy to see that $n=3$ satisfies the solution. We will prove that this the only solution.
Suppose for the sake of contradiction that $p \geqslant 5$ is a prime divisor of $n$. The original problem reduces to finding $n$ such that $$\large v_p(n^2) \leqslant v_p(2^n+1)$$ Observe that $n$ is odd and since $v_p(x^n+y^n)=v_p(x+y)+v_p(n)$, for odd $n$, $$\large v_p(2^n+1)=v_p(2+1)+v_p(n)$$
Since by our assumption $p \geqslant 5$ therefore $v_p(1+2)=v_p(3)=0$. And hence $$\large v_p(2^n+1)=v_p(n)$$ But this implies $$\large v_p(n^2) > v_p(n)$$ which is absurd. Therefore the only solution is $n=3$.
Is my solution valid? I'm quite new to lifting the exponent lemma. I read it in Evan Chen's handout titled 'Orders Modulo a Prime' and was pretty fascinated at the fact that it could be used to solve at least easy-moderate Olympiad problems. Please verify and see if I missed out something obvious. Also, I have not included a proof of the lemma as I think it would be pretty useless here :) Thank you.
You were on the right track but, as you acknowledged in the question comments, you can't use $p \ge 5$ in your case with the Lifting-the-exponent lemma (LTE) since $p \not\mid 1 + 2 = 3$. Instead, first use that
$$n^2 \mid 2^n + 1 \tag{1}\label{eq1A}$$
obviously requires $n \mid 2^n + 1$ (useful details about this are in When does $n$ divide $2^n+1$?).
Next, Primitive elements of the sequence of integers n such that n divides 2^n + 1 says
Note that $27 = 3^3$ and $171 = 3^2\left(19\right)$. In particular, this means that each such primitive element $\gt 3$ has at least $2$ factors of $3$. In addition, Numbers n such that n divides 2^n + 1 states that, apart from the primitive elements, all other elements are generated among themselves by one of $3$ methods, i.e., multiplication of two elements, multiple of an element having the same prime factors as the element, and the lowest common multiple of two elements. Generating any element using $3$ will result in a number with at least two factors of $3$. Also, note using any of the $3$ methods will not reduce the number of factors of $3$ in the generated element. Thus, this shows that all $n$ other than $1$ and $3$ must have at least $2$ factors of $3$.
Since $n$ is odd, $3 \not\mid 1$ and $3 \not\mid 2$, but $3 \mid 1 + 2 = 3$, the LTE can be used to determine limits on the power of $3$ in $n$. Using $p = 3$,
$$\nu_3\left(2^n + 1\right)= \nu_3(2 + 1) + \nu_3(n) = 1 + \nu_3(n) \tag{2}\label{eq2A}$$
For \eqref{eq1A} to hold requires
$$\nu_3\left(2^n + 1\right) \ge 2\nu_3(n) \tag{3}\label{eq3A}$$
As such, \eqref{eq2A} shows that
$$1 + \nu_3(n) \ge 2\nu_3(n) \; \; \to \; \; 1 \ge \nu_3(n) \tag{4}\label{eq4A}$$
Since \eqref{eq4A} shows $n$ can have only up to $1$ factor of $3$, but since all $n \gt 3$ have at least $2$ factors of $3$, this proves $n = 1$ and $n = 3$ are the only solutions to \eqref{eq1A}.