$\sum_{k=1}^n\frac{1}{\sin^2\left(\frac{(2k+1)\pi}{2n}\right)}$ How to calculate this sum 
$$S_n = \sum_{k=1}^n\frac{1}{\sin^2\left(\frac{(2k+1)\pi}{2n}\right)} ?$$ 
Note : 
1) 
$$S_n = n+\sum_{k=1}^n{\rm cotan}^2\left(\frac{(2k+1)\pi}{2n}\right)$$
2) $S_n$ seems to be equal to $\frac{n^2}{4}$.
3) I kwow how to calculate 
$$\sum_{k=1}^n\frac{1}{\sin^2\left(\frac{k\pi}{2n}\right)}$$
with the roots of $(X+1)^{2n} - (X-1)^{2n}$.
 A: Hint 1: If you know the answer for $\sum\limits_{k=1}^{2n-1}\csc^2\left(\frac{k}{2n}\pi\right)$, then use
$$
\sum_{k=1}^n\csc^2\left(\frac{2k-1}{2n}\pi\right)+\sum_{k=1}^{n-1}\csc^2\left(\frac{k}{n}\pi\right)=\sum_{k=1}^{2n-1}\csc^2\left(\frac{k}{2n}\pi\right)
$$
Hint 2: $\frac{2n/z}{z^{2n}-1}$ has residue $1$ at $z=e^{\pi ik/n}$ and residue $-2n$ at $z=0$.

Apply Hint 2
$$
\begin{align}
\left(\frac{2i}{z-\frac1z}\right)^2\frac{2n/z}{z^{2n}-1}
&=\frac{-4z^2}{z^4-2z^2+1}\frac{2n/z}{z^{2n}-1}\\
&=\left(\frac1{(z+1)^2}-\frac1{(z-1)^2}\right)\frac{2n}{z^{2n}-1}
\end{align}
$$
has residue $\csc^2\left(\pi k/n\right)$ at $z=e^{\pi ik/n}$ except at $z=\pm1$. A bit of computation gives
$$
\begin{align}
\frac{2n}{z^{2n}-1}
&=\phantom{+}\frac1{z-1}-\frac{2n-1}2+\frac{(2n-1)(2n+1)}{12}(z-1)+O\!\left((z-1)^2\right)\\
&=-\frac1{z+1}-\frac{2n-1}2-\frac{(2n-1)(2n+1)}{12}(z+1)+O\!\left((z+1)^2\right)
\end{align}
$$
Therefore,
$$\newcommand{\Res}{\operatorname*{Res}}
\Res_{z=1}\left(\frac1{(z+1)^2}-\frac1{(z-1)^2}\right)\frac{2n}{z^{2n}-1}
=\frac14-\frac{4n^2-1}{12}=-\frac{n^2-1}3
$$
and
$$
\Res_{z=-1}\left(\frac1{(z+1)^2}-\frac1{(z-1)^2}\right)\frac{2n}{z^{2n}-1}
=\frac14-\frac{4n^2-1}{12}=-\frac{n^2-1}3
$$
Since the sum of the residues at all the singularities is $0$, we get that half the sum over the singularities except at $z=\pm1$ is
$$
\sum_{k=1}^{n-1}\csc^2\left(\frac{k}{n}\pi\right)=\frac{n^2-1}3
$$

Apply Hint 1
$$
\begin{align}
\sum_{k=1}^n\csc^2\left(\frac{2k-1}{2n}\pi\right)
&=\sum_{k=1}^{2n-1}\csc^2\left(\frac{k}{2n}\pi\right)
-\sum_{k=1}^{n-1}\csc^2\left(\frac{k}{n}\pi\right)\\
&=\frac{4n^2-1}3-\frac{n^2-1}3\\[9pt]
&=n^2
\end{align}
$$
A: Take a polynomial $P(t)=t^n$ and consider the function $$F_t(z)=\frac{P(tz)-P(t)}{z-1}=t^n\frac{z^n-1}{z-1}.$$
Lagrange interpolation of $F_t$ with basis points on the roots $z_0,z_1,...,z_{n-1}$ of $z^n+1$ (so that $z_k=e^{\frac{\pi(1+2k)}{n}}$) gives:
$$
F_t(z)=\sum_{k=0}^{n-1} F_t(z_k)\frac{z^n+1}{nz_k^{n-1}(z-z_k)}=-\frac{1}{n}\sum_{k=0}^{n-1}t^n\frac{z_k^n-1}{z_k-1}\frac{z^n+1}{z-z_k}z_k=\\
=-\frac{1}{n}\sum_{k=0}^{n-1}t^n\frac{2}{z_k-1}\frac{z^n+1}{z_k-z}z_k.
$$
On one hand $F_t(1)=tP'(t)=nt^n$ and on the other $F_t(1)=-\frac{1}{n}\sum_{k=0}^{n-1}t^n\frac{4z_k}{(z_k-1)^2}$.
Thus
$$
n^2=-4\sum_{k=0}^{n-1}\frac{z_k}{(z_k-1)^2}=\sum_{k=0}^{n-1}\frac{1}{\sin^2\left(\frac{\pi(1+2k)}{2n}\right)}
$$
since $\frac{e^{i\phi}}{(e^{i\phi}-1)^2}=-\frac{1}{4\sin^2 \phi/2}$.
