6. For $n \in \mathbf{N}^{*}$, let $S_{n}$ be the minimum value of $\sum_{k=1}^{n} \sqrt{(2 k-1)^{2}+a_{k}^{2}}$, where $a_{1}, a_{2}, \cdots, a_{n} \in \mathbf{R}^{+}$, and $\sum_{k=1}^{n} a_{k}=17$. If there exists $n$ such that $S_{n}$ is also an integer, find all values of $n$.
6. From $\sqrt{(2 k-1)^{2}+a_{k}^{2}}=\left|(2 k-1)+a_{k} i\right|, k=1,2, \cdots, n$, we get $\sum_{k=1}^{n} \sqrt{(2 k-1)^{2}+a_{k}^{2}}=\sum_{k=1}^{n} \mid(2 k$ $-1)+a_{k} i\left|\geqslant 1 \sum_{k=1}^{n}(2 k-1)+\left(\sum_{k=1}^{n} a_{k}\right) i\right|=\left|n^{2}+17 i\right|=\sqrt{n^{4}+17^{2}}$, the equality can be achieved, so $S_{n}=$ $\sqrt{n^{4}+17^{2}}>0$.
If $S_{n} \in \mathbf{Z}$, then $\left(S_{n}-n^{2}\right)\left(S_{n}+n^{2}\right)=17^{2}$, thus $S_{n}-n^{2}=1$ and $S_{n}+n^{2}=17^{2}$, solving these gives $n=12$.