TITLE: Prove that $\sum\limits_{k=0}^{n-1}\dfrac{1}{\cos^2\frac{\pi k}{n}}=n^2$ for odd $n$
QUESTION [25 upvotes]: In old popular science magazine for school students I've seen problem

Prove that $\quad $
  $\dfrac{1}{\cos^2 20^\circ} + 
\dfrac{1}{\cos^2 40^\circ} + 
\dfrac{1}{\cos^2 60^\circ} + 
\dfrac{1}{\cos^2 80^\circ} = 40. $

How to prove more general identity:
$$
\begin{array}{|c|}
\hline \\
\sum\limits_{k=0}^{n-1}\dfrac{1}{\cos^2\frac{\pi k}{n}}=n^2 \\
\hline
\end{array}
,  \qquad \mbox{ where } \ n \ \mbox{ is odd.}$$

REPLY [6 votes]: In equation $(7)$ of this answer, I compute that
$$
\sum_{k=1}^n\tan^2\left(\frac{k\pi}{2n+1}\right)=n(2n+1)
$$
Thus, with $n=2m+1$,
$$
\begin{align}
\sum_{k=0}^{n-1}\frac1{\cos^2\left(\frac{k\pi}{n}\right)}
&=\sum_{k=0}^{2m}\sec^2\left(\frac{k\pi}{2m+1}\right)\\
&=2\sum_{k=0}^m\tan^2\left(\frac{k\pi}{2m+1}\right)+2(m+1)\\[6pt]
&=2m(2m+1)+2(m+1)\\[12pt]
&=(2m+1)^2\\[12pt]
&=n^2
\end{align}
$$

Residue Theory Answer

For odd $n$, consider the function
$$
f(z)=\frac{n/z}{z^n-1}\left(\frac{z-1}{z+1}\right)^2\tag{1}
$$
All the singularities are simple, except the singularity at $-1$.
$$
\left(\frac{z-1}{z+1}\right)^2=1-\frac4{z+1}+\frac4{(z+1)^2}\tag{2}
$$
Furthermore,
$$
\frac{\mathrm{d}}{\mathrm{d}z}\frac{n/z}{z^{\raise{2pt}n}-1}=\frac{n-n(n+1)z^n}{z^2(z^{\raise{2pt}n}-1)^2}\tag{3}
$$
Using $(2)$ and $(3)$, we get the residue of $f$ at $-1$ to be
$$
-4\cdot\frac{-n}{-1-1}+4\cdot\frac{n+n(n+1)}{(-1-1)^2}=n^2\tag{4}
$$
The residue of $f$ at $0$ is $-n$ and the residue at each $n^{\text{th}}$ root of unity is $-\tan^2(\theta/2)$.

Since the integral of $f$ over an increasing circle vanishes, the sum of the residues must be $0$. Therefore,
$$
\sum_{k=0}^{n-1}\tan^2\left(\frac{k\pi}{n}\right)=n^2-n\tag{5}
$$
and therefore,
$$
\sum_{k=0}^{n-1}\sec^2\left(\frac{k\pi}{n}\right)=n^2\tag{6}
$$