Four, (50 points) Find all integers $a$, such that there exist distinct positive integers $x, y$, satisfying $(a x y+1) \mid\left(a x^{2}+1\right)^{2}$.


For all $a \geqslant-1$.

First, $a=0$ is obviously true.
If $a \neq 0$, then
$$
\begin{array}{l}
(a x y+1) \mid\left(a x^{2}+1\right)^{2} \\
\Leftrightarrow(a x y+1) \mid\left(a^{2} x^{4}+2 a x^{2}+1\right) \\
\Leftrightarrow(a x y+1) \mid\left(a^{2} x^{4}+2 a x^{2}-a x y\right) \\
\Leftrightarrow(a x y+1) \mid a x\left(a x^{3}+2 x-y\right) \\
\Leftrightarrow(a x y+1) \mid\left(a x^{3}+2 x-y\right)((a x y+1, \\
a x)=1) \\
\Leftrightarrow(a x y+1) \mid\left(a x^{3}+2 x+a x y^{2}\right) \\
\Leftrightarrow(a x y+1) \mid\left(a x^{2}+2+a y^{2}\right)((a x y+1, \\
x)=1) \\
\Leftrightarrow(a x y+1) \mid\left(a x^{2}-2 a x y+a y^{2}\right) \\
\Leftrightarrow(a x y+1) \mid\left(x^{2}-2 x y+y^{2}\right)((a x y+1 \\
a)=1) .
\end{array}
$$

When $a>0$, take $x=1, y=a+2$, then $(a+1)^{2} \mid(a+1)^{2}$, which satisfies the requirement;
When $a=-1$, take $x=2, y=1$, it also satisfies the requirement.
When $a \leqslant-2$, let
$$
x^{2}-2 x y+y^{2}=-t(a x y+1) \quad\left(t \in \mathbf{Z}_{+}\right) \text {. }
$$

Below, we prove that the following equation in $x, y$
$$
x^{2}+(a t-2) y x+y^{2}+t=0
$$

has no positive integer solutions.
Assume the equation (1) has positive integer solutions, and let $\left(x_{0}, y_{0}\right)$ be the solution that minimizes $x_{0}+y_{0}$.

By symmetry, assume $x_{0} \geqslant y_{0}$. Fix $y_{0}$ and consider equation (1) as a quadratic equation in $x$, with roots $x_{0}, x_{1}$.
By Vieta's formulas, we have
$$
\left\{\begin{array}{l}
x_{0}+x_{1}=(2-a t) y_{0} \\
x_{0} x_{1}=y_{0}^{2}+t .
\end{array}\right.
$$

From (2), $x_{1}$ is an integer, and from (3), $x_{1}$ is a positive integer, so $x_{1}=\frac{y_{0}^{2}+t}{x_{0}} \geqslant x_{0}$ (by minimality).
$$
\begin{array}{l}
\text { Hence } t \geqslant x_{0}^{2}-y_{0}^{2}=\left(x_{0}-y_{0}\right)\left(x_{0}+y_{0}\right) \\
>\left(x_{0}-y_{0}\right)^{2},
\end{array}
$$

which contradicts $t \mid\left(x_{0}-y_{0}\right)^{2}$.