8. (1999 National High School Competition Question) Given a positive integer $n$ and a positive number $M$, for all arithmetic sequences $a_{1}, a_{2}, a_{3}, \cdots$ satisfying the condition $a_{1}^{2}+a_{n+1}^{2} \leqslant M$, find the maximum value of $S=a_{n+1}+a_{n+2}+\cdots+a_{2 n+1}$.
8. Let the common difference be $d$, then from the given condition we have $\left(a_{n+1}-n d\right)^{2}+a_{n+1}^{2} \leqslant M$, which means $2 a_{n+1}^{2}-2 n d a_{n+1}+n^{2} d^{2} \leqslant M$, thus $\left(a_{n+1}-\frac{n}{2} d\right)^{2}+\left(\frac{n}{2} d\right)^{2} \leqslant \frac{M}{2}$.
Let $\vec{a}=(1,2), \vec{b}=\left(a_{n+1}-\frac{n}{2} d, \frac{n}{2} d\right)$.
By $|\vec{a} \cdot \vec{b}| \leqslant|\vec{a}||\vec{b}|$, we get
$$
\begin{array}{l}
\quad\left|a_{n+1}+\frac{n}{2} d\right|=\left|\left(a_{n+1}-\frac{n}{2} d\right)+2 \cdot \frac{n}{2} d\right| \\
\leqslant \sqrt{1^{2}+2^{2}} \cdot \sqrt{\left(a_{n+1}-\frac{n}{2} d\right)^{2}+\left(\frac{n}{2} d\right)^{2}} \leqslant \sqrt{5} \cdot \sqrt{\frac{M}{2}}=\frac{\sqrt{10 M}}{2} .
\end{array}
$$

Therefore, $S=a_{n+1}+a_{n+2}+\cdots+a_{2 n+1}=(n+1) a_{n+1}+\frac{n(n+1)}{2} d=(n+1)\left(a_{n+1}+\frac{n}{2} d\right)$
$$
\leqslant(n+1)\left|a_{n+1}+\frac{n}{2} d\right| \frac{n+1}{2} \sqrt{10 M}
$$

The inequality holds with equality if and only if $\frac{n}{2} d=2\left(a_{n+1}-\frac{n}{2} d\right)$, and $a_{n+1}+\frac{n}{2} d>0,\left(a_{n+1}-\frac{n}{2} d\right)^{2}+\left(\frac{n}{2} d\right)^{2}=\frac{M}{2}$. Solving these, we get $a_{n+1}=\frac{3}{10} \sqrt{10 M}, d=\frac{2}{5 n} \sqrt{10 M}$.
Thus, the maximum value of $S$ is $\frac{n+1}{2} \sqrt{10 M}$.