Four, (50 points) Find all positive integers $n$, such that $\frac{n+1}{2}$ and $\frac{n^{2}+1}{2}$ are both perfect squares.

 untranslated part:
(50 points) Find all positive integers $n$, such that $\frac{n+1}{2}$ and $\frac{n^{2}+1}{2}$ are both perfect squares.
Obviously, the following two conclusions hold.

Conclusion 1: The indeterminate equation $x^{4}+y^{4}=z^{2}$ has no integer solutions for $x y \neq 0$.

Conclusion 2: The indeterminate equation $x^{4}-y^{4}=z^{2}$ has no integer solutions for $y z \neq 0$.
Let $a^{2}=\frac{n+1}{2}, b^{2}=\frac{n^{2}+1}{2}$. Then
$n=2 a^{2}-1 \Rightarrow \frac{\left(2 a^{2}-1\right)^{2}+1}{2}=b^{2}$
$\Rightarrow 2 a^{4}-2 a^{2}+1=b^{2}$
$\Leftrightarrow\left(a^{2}\right)^{2}+\left(a^{2}-1\right)^{2}=b^{2}$.
If $a=1$, then $b=1$, at this time, $n=1$.
Upon verification, it satisfies the conditions.
Assume $a \geqslant 2$.
Since $\left(a^{2}, a^{2}-1\right)=1$, there exist positive integers
$c>d,(c, d)=1, c, d$ one odd and one even, such that
$\left\{\begin{array}{l}a^{2}=2 c d, \\ a^{2}-1=c^{2}-d^{2} \\ b=c^{2}+d^{2}\end{array}\right.$, or $\left\{\begin{array}{l}a^{2}=c^{2}-d^{2}, \\ a^{2}-1=2 c d, \\ b=c^{2}+d^{2} .\end{array}\right.$
(1) If $a$ is even, let $a=2 m$, then
$$
\left\{\begin{array}{l}
2 m^{2}=c d, \\
4 m^{2}-1=c^{2}-d^{2}, \\
b=c^{2}+d^{2} .
\end{array}\right.
$$

From $c^{2}-d^{2}=4 m^{2}-1 \equiv-1(\bmod 4)$
$\Rightarrow c$ is even, $d$ is odd.
Thus, there exist positive integers $e, f,(e, f)=1$, such that $c=2 e^{2}, d=f^{2}, m=e f$.
Hence $4(e f)^{2}-1=4 e^{4}-f^{4}$
$\Rightarrow f^{4}+4(e f)^{2}+4 e^{4}-1=8 e^{4}$
$\Leftrightarrow \frac{f^{2}+2 e^{2}+1}{2} \cdot \frac{f^{2}+2 e^{2}-1}{2}=2 e^{2}$.
Note that, $\left(\frac{f^{2}+2 e^{2}+1}{2}, \frac{f^{2}+2 e^{2}-1}{2}\right)=1$.
Thus, there exist positive integers $g, h$, such that
$\left\{\begin{array}{l}\frac{f^{2}+2 e^{2}+1}{2}=2 g^{4} \\ \frac{f^{2}+2 e^{2}-1}{2}=h^{4}, \\ g h=e\end{array}\right.$
or $\left\{\begin{array}{l}\frac{f^{2}+2 e^{2}+1}{2}=h^{4}, \\ \frac{f^{2}+2 e^{2}-1}{2}=2 g^{4}, \\ g h=e .\end{array}\right.$
(i) If equation set (1) holds, then
$2 g^{4}-h^{4}=1 \Rightarrow\left(g^{2}\right)^{4}-h^{4}=\left(g^{4}-1\right)^{2}$.
According to Conclusion 2,
$h\left(g^{4}-1\right)=0 \Rightarrow g=1$
$\Rightarrow h=1 \Rightarrow e=1, f=1, m=1, a=2$.
Thus, $n=7$. Upon verification, it satisfies the conditions.
(ii) If equation set (2) holds, then
$h^{4}-2 g^{4}=1 \Rightarrow h^{4}+\left(g^{2}\right)^{4}=\left(g^{4}+1\right)^{2}$.
According to Conclusion 1, we know $h g=0$, which contradicts $g, h$ being positive integers.