Simplifying a summation involving "cos". $\sum_{r=1}^{n-1}\cos ^{2}\left ( \frac{r\pi }{n} \right )$
How can I simplify this summation when I do not know whether "n" is odd or even?

If $\displaystyle S=\sum_{r=1}^{n-1}\cos ^2\left ( \frac{r\pi }n \right )$
$\displaystyle 2S=\sum_{r=1}^{n-1}[1+\cos \frac{2r\pi }n ]=n-1+\sum_{r=1}^{n-1}\cos \frac{2r\pi }n=n-1-1+\sum_{r=0}^{n-1}\cos \frac{2r\pi }n$
Now if $\displaystyle\cos(nx)=1,nx=2m\pi$ where  $m$ is any integer
$\displaystyle x=\frac{2m\pi}n$ where $0\le m\le n-1$
Now using the pattern here,  $\displaystyle\cos(nx)=2^{n-1}\cos^nx+0\cdot\cos^{n-1}x\cdots=0$
If we set $\cos(nx)=1,$  the roots of $\displaystyle2^{n-1}\cos^nx+0\cdot\cos^{n-1}x\cdots-1=0$ are  $\displaystyle\cos\frac{2m\pi}n$ where $0\le m\le n-1$
So, using Vieta's formula, $\displaystyle\sum_{m=0}^{n-1}\cos\frac{2m\pi}n=\frac0{2^{n-1}}$
