I have managed to proove the first part but i got stuck on the second part of this excercise:
Let us demonstrate that for a secure RSA modulus $n = pq$, the difference $|p − q|$ should
not be too small.
(a) Let $q − p = 2d > 0$. Prove that $n + d^2$
is a perfect square.
(b) Suppose that there exists a small integer $d$ such that $n + d^2$
is a perfect square. Show how $n$ can be
factorized.
You know that $n+d^2$ is a perfect square, i.e. $n+d^2=m^2$ for some positive integer $m$. You can find $m$ by computing $\sqrt{n+d^2}$, which is easy. Then $n=m^2-d^2=(m+d)(m-d)$, so $q=m+d$ and $p=m-d$.