Prove that $\left|\left\{ 1\leq x\leq p^{2}\ :\ p^{2}\mid\left(x^{p-1}-1\right)\right\} \right|=p-1$ Let $p$ be a prime number and to simplify things lets denote
$$
A=\left\{ 1\leq x\leq p^{2}\ :\ p^{2}\mid\left(x^{p-1}-1\right)\right\}
$$
and we have to show that $\left|A\right|=p-1$.
For every $x\in A$ we know that $p^{2}\mid\left(x^{p-1}-1\right)$
which means $x^{p-1}-1=kp$ for some $k\in\mathbb{Z}$, and as this is
a polynomial of degree $p-1$ it has at most $p-1$ solutions. Therefore $\left|A\right|\leq p-1$.
How can we show there are exactly $p-1$ solutions in $A$?
 A: Let's fix an integer $a$ in ther range $1\le a<p$. By Little Fermat we know that $a^{p-1}\equiv1\pmod p$. We use this to study the number of solutions $x\in A$ such that $x\equiv a\pmod p$.
So let $x=a+kp$ for some $k$, $0\le k<p$. The binomial theorem tells us that
$$
\begin{aligned}
x^{p-1}&=(a+kp)^{p-1}\\
&=a^{p-1}+\binom {p-1}1a^{p-2}kp+\sum_{i=2}^{p-1}\binom {p-1}ia^{p-1-i}k^ip^i.
\end{aligned}
$$
Here all the terms in the last sum are divisible by $p^2$, so we get that
$$
(a+kp)^{p-1}\equiv a^{p-1}+(p-1)a^{p-2}kp\pmod{p^2}.\qquad(*)
$$
Little Fermat tells us that $a^{p-1}=1+s_ap$ for some integer $s_a$. Therefore $(*)$ tells us that $(a+kp)^{p-1}$ is congruent to $1$ modulo $p^2$ if and only if 
$$s_a+(p-1)a^{p-2}k\equiv0\pmod p.\qquad(**)$$
Here the coefficient $(p-1)a^{p-2}$ is not divisible by $p$ so by the basic theory of linear congruences  $(**)$ is satisfied for exactly one choice of $k$ in the range $0\le k<p$.
The claim follows from this because $p\mid x\implies x^{p-1}\not\equiv1\pmod p.$
