Help to compute the following coefficient in Fourier series $\int_{(2n-1)\pi}^{(2n+1)\pi}\left|x-2n\pi\right|\cos(k x)\mathrm dx$ 
$$\int_{(2n-1)\pi}^{(2n+1)\pi}\left|x-2n\pi\right|\cos(k x)\mathrm dx$$
  where $k\geq 0$, $k\in\mathbb{N} $ and $n\in\mathbb{R} $.

it is a $a_k$ coefficient in a Fourier series.

\begin{eqnarray}
a_k&=&\int_{(2n-1)\pi}^{(2n+1)\pi}|x-2n\pi|\cos(kx)\,dx=\int_{-\pi}^{\pi}|x|\cos(kx+2kn\pi)\,dx\\
&=&\int_{-\pi}^\pi|x|\left[\cos(2kn\pi)\cos(kx)-\sin(2knx)\sin(kx)\right]\,dx\\
&=&\int_{-\pi}^\pi|x|\cos(2kn\pi)\cos(kx)\,dx=2\cos(2kn\pi)\int_0^\pi x\cos(kx)\,dx\\
&=&\frac{2\cos(2kn\pi)x\sin(kx)}{k}\Big|_0^\pi-\frac{2\cos(2kn\pi)}{k}\int_0^\pi\sin(kx)\,dx\\
&=&\frac{2\cos(2kn\pi)}{k^2}\cos(kx)\Big|_0^\pi=2\frac{(-1)^k-1}{k^2}\cos(2kn\pi).
\end{eqnarray}
NB: When I first answered the question I did not notice the condition $n \in \mathbb{R}$ and just assumed that $n \in \mathbb{Z}$.
