4. Calculate:
$$
\cos ^{2} \frac{\pi}{17}+\cos ^{2} \frac{2 \pi}{17}+\cdots+\cos ^{2} \frac{16 \pi}{17}=
$$
$\qquad$
4. $\frac{15}{2}$.

Let the desired sum be $S$. Then
$$
\begin{array}{l}
2 S=\sum_{k=1}^{16}\left(1+\cos \frac{2 k \pi}{17}\right) \\
\Rightarrow 2 S-16=\sum_{k=1}^{16} \cos \frac{2 k \pi}{17} \\
\Rightarrow(2 S-16) 2 \sin \frac{\pi}{17}=\sum_{k=1}^{16} 2 \cos \frac{2 k \pi}{17} \cdot \sin \frac{\pi}{17} \\
=\sum_{k=1}^{16}\left(\sin \frac{(2 k+1) \pi}{17}-\sin \frac{(2 k-1) \pi}{17}\right) \\
=\sin \frac{33 \pi}{17}-\sin \frac{\pi}{17}=-2 \sin \frac{\pi}{17} \\
\Rightarrow 2 S-16=-1 \Rightarrow S=\frac{15}{2} \text {. } \\
\end{array}
$$