Divisbility problem: If $n>1$ satisfies $p^n\equiv (p-1)^n+1\pmod{n^2}$ for every prime $pLet $n>1$ be an integer such that for every   prime $p<n$ , $n^2 | (p-1)^n +1 - p^n$ ; then is it true that $n=2$  ? 
I can only see that $p^2 | (p-1)^n + 1$ if $n>1$ is not a prime and $p|n$.  I have no idea how to approach. Please help. Thanks in advance  
 A: This is a nice problem. First we'll use induction to show that prove that no prime $p<n$ can divide $n,$ and hence $n$ must be prime. Then we'll obtain a contradiction for $n>2$ using Hensel's lemma.

Lets rewrite the given condition as $$p^n\equiv (p-1)^n+1\pmod{n^2}$$ for every $p<n$.

Proposition: We have that $$k^n\equiv k \pmod{n^2}$$ for every $k$ which is a product of primes $p_i<n$. 


Proof: The base case $k=2$ follows immediately from the condition. If $k>2$ is prime, we know that $$k^n\equiv (k-1)^n+1 \pmod{n^2}.$$ By the inductive hypothesis, we have that $$(k-1)^n\equiv k-1\pmod {n^2},$$ and hence the result for $k$ follows by substitution. If $k$ is a composite, say $k=p_1^{\alpha_1}\cdots p_r^{\alpha_r}$, then by induction we have that $$p_i^n\equiv p_i \pmod{n^2},$$ for every $p_i$ which divides $k$, and hence  $$\left(p_1^{\alpha_1}\cdots p_r^{\alpha_r}\right)^n=(p_1^n)^{\alpha_1}\cdots(p_r^n)^{\alpha_r}\equiv k=p_1^{\alpha_1}\cdots p_r^{\alpha_r} \pmod{n^2},$$ which proves the proposition. 

This implies that for every $p<n$, $$p\cdot(p^{n-1}-1)\equiv 0\pmod{n^2},$$ and hence $p\nmid n$ since this congruence is modulo $n^2$. Thus $n$ must be prime, and furthermore it has to satisfy $$x^{n}-x\equiv 0 \pmod{n^2}$$ for every $1\leq x\leq n-1$. Let $P(x)=x^n-x$. Then we know that this is always $0$ modulo $n$, and since this polynomial has derivative equal to $-1$ modulo $n$, it follows from Hensel's lemma that every root modulo $n$ lifts uniquely modulo $n^2$. Since $P(x)\equiv 0\pmod{n^2}$ for $1\leq x\leq n-1$ by the proposition, we know exactly what the unique lifts of these roots are. The integer $n+1$ will not be prime for $n>2$, and so it can be factored into a product of primes less than $n$, and by the proposition we have that $$(n+1)^n-(n+1)\equiv 0\pmod{n^2}.$$ This contradicts the fact that the root $1$ modulo $n$ lifted uniquely, which finishes the proof.
