Example 4 Determine all pairs of positive integers $(n, p)$ such that: $p$ is a prime, $n \leqslant 2 p$, and $n^{p-1} \mid\left[(p-1)^{n}+1\right]$.
(40th IMO)
(1) When $n=1$, obviously, any prime $p$ satisfies the condition.
(2) When $n=2$, since $n^{p-1} \mid\left[(p-1)^{n}+1\right]$, thus, $(p-1)^{n}+1$ is even.
Therefore, $p$ is even, and can only be $p=2$.
Upon verification, $(n, p)=(2,2)$ satisfies the condition.
(3) When $n \geqslant 3$, obviously, $p \geqslant 3$.
At this point, $(p-1)^{n}+1$ is odd.
So, $n$ is odd.
Let the smallest prime factor of $n$ be $q$. Then
$$
(p-1)^{n} \equiv-1(\bmod q) \text {. }
$$

Let the half-order of $p-1$ modulo $q$ be $\tau$. Then $\tau \mid n$, and the order of $p-1$ modulo $q$ is $2 \tau$.
Also, $\varphi(q)=q-1$, then
$$
2 \tau \mid (q-1) \Rightarrow \tau \mid (q-1) \text {. }
$$

Thus, $\tau \mid (n, q-1)$.
Noting that $q$ is the smallest prime factor of $n$.
Thus, $(n, q-1)=1$.
Therefore, $\tau=1$.
Hence $p-1 \equiv-1(\bmod q) \Rightarrow q \mid p \Rightarrow q=p$
$\Rightarrow p$ is the smallest prime factor of $n$.
Since $n \leqslant 2 p$, thus, only $n=p$.
Therefore, $p^{p-1} \mid\left[(p-1)^{p}+1\right]$.
By the binomial theorem,
$$
\begin{array}{l}
(p-1)^{p}+1 \\
=p^{p}-\mathrm{C}_{p}^{1} p^{p-1}+\mathrm{C}_{p}^{2} p^{p-2}-\mathrm{C}_{p}^{3} p^{p-3}+\cdots+\mathrm{C}_{p}^{p-1} p-1+1 \\
=p^{2}\left(p^{p-2}-\mathrm{C}_{p}^{1} p^{p-3}+\mathrm{C}_{p}^{2} p^{p-4}-\mathrm{C}_{p}^{3} p^{p-5}+\cdots\right. \\
\left.\quad-\mathrm{C}_{p}^{p-2}+1\right) .
\end{array}
$$

Clearly, $p^{2} \mid\left[(p-1)^{p}+1\right]$, and
$$
p^{3} \mid \left[(p-1)^{p}+1\right] \text {. }
$$

Therefore, $p-1 \leqslant 2$, which gives $p=3$.
In summary, all solutions are
$(n, p)=(2,2),(3,3),(1, p)(p$ is any
prime).