6. Find all $n \geqslant 2\left(n \in \mathbf{Z}_{+}\right)$, such that $n$ can be written as $n=k^{2}+d^{2}$, where $k$ is the smallest prime factor of $n$, and $d$ is a factor of $n$ greater than 1.
6. Notice that,
$k|n, k| k^{2} \Rightarrow k|d^{2} \Rightarrow k| d$. Let $g$ be any prime factor of $d$. Then $g|d, g| n \Rightarrow g \mid k^{2} \Rightarrow g=k$ $\Rightarrow d$ has only the prime factor $k$.
Let $d=k^{s}$. Then $k^{2} \| n$.
Notice that, $k^{s} \mid n$. Hence $s \leqslant 2$.
(1) When $s=1$, $n=k^{2}(1+1)=2 k^{2}$.

Since $k$ is the smallest prime factor of $n$, we have,
$$
k=2 \Rightarrow n=8 \text {. }
$$
(2) When $s=2$, $n=k^{2}\left(k^{2}+1\right)$.

Since $k$ is the smallest prime factor of $n$, $k^{2}+1$ has only factors greater than $k$.

If $k^{2}+1$ is composite, then $k^{2}+1 \geqslant(k+1)^{2}$, which is impossible.
Thus, $k^{2}+1$ is prime.
When $k(k \geqslant 3)$ is an odd prime, $k^{2}+1$ is an even number greater than 2, and is not prime.
Therefore, $k=2, n=4 \times 5=20$.
In summary, $n=8$ or 20.