Does $x^2\equiv x\pmod p$ imply $x^2\equiv x\pmod {p^n}$ for all $n$? Suppose $x^2\equiv x\pmod p$ where $p$ is a prime, then is it generally true that $x^2\equiv x\pmod {p^n}$ for any natural number $n$? And are they the only solutions?

Way 1: Let us compute a bit. Let $p=2$. Note that $x^2\equiv x \pmod 2$ for any $x$. Is it true that always $x^2\equiv x\pmod 4$? No, let $x=2$.
Way 2: We  do more work, but will get a lot more information. Rewrite the congruence $x^2\equiv x \pmod p$ as $x^2-x\equiv 0 \pmod p$, and then as $x(x-1)\equiv 0\pmod p$.
This says that the product of $x$ and $x-1$ is divisible by $p$. A product $ab$ is divisible by the prime $p$ if and only if $p$ divides $a$ or $p$ divides $b$, or both.  
So $x(x-1)$ is divisible by $p$ if and only if $x$ is divisible by $p$ or $x-1$ is divisible by $p$, that is, if and only if $x\equiv 0 \pmod p$ or $x\equiv 1 \pmod p$.
Now does this force $x(x-1) \equiv 0 \pmod {p^2}$?  No, for example we could take $x=p$. Certainly it is not true that $p(p-1)$ is divisible by $p^2$.  We could also take $x=2p$, or $x=3p$, and so on up to $x=(p-1)p$. Or we could put the badness in the $x-1$ part, by putting $x=1+p$, or $x=1+2p$, and so on up to $x=1+(p-1)p$.  We get a total of $2(p-1)$ numbers $x$ between $0$ and $p^2-1$ such that $x^2\equiv x \pmod p$ but $x^2\not\equiv x \pmod{p^2}$.  
We can similarly identify the numbers $x$ between $0$ and $p^n-1$ such that $x(x-1)\equiv 0 \pmod p$ but $x(x-1)\not \equiv 0 \pmod{p^n}$. Again, they are of two types: (i) the numbers $p$, $2p$, and so on up to $p(p^{n-1}-1)$ and (ii) the numbers obtained by adding $1$ to numbers in list (i).
