7. Find all primes $p$ and natural numbers $n$ that satisfy the equation $p^{2}+n^{2}=3 p n+1$.
Solution. Obviously, $n^{2}-1=p(3 n-p)$, that is, $n$ is equal to $\pm 1$ modulo $p$. Substitute $n=a p \pm 1$ into the equation, after transformations we get

$$
\left(a^{2}+1-3 a\right) p^{2}= \pm(3-2 a) p
$$

Thus, $(3-2 a) \vdots p$.

If $a=0$, we get the solution $p=3, n=1$.

Otherwise, $a \geqslant 3$. On the other hand, $n \leqslant 3 p$, otherwise the right-hand side of the original equation is greater than the left. Then $n$ can only be equal to $3 p-1$, from which it easily follows that $p=3, n=8$.