The Fourier series of $f(x) = \cos(x)$ on $|x| < \pi/2$ and $f(x) = 0$ otherwise.
Since $\cos(x) = \cos(-x)$, we have $b_n=0$.
Then I computed 2 different $a_0$'s, thinking the latter one is the correct one but not quite sure why the first one is incorrect since outside the interval $|x| < \pi/2$, we have that the function is zero.
$a_0 = \frac{1}{\pi}\int_{-\pi}^{\pi}\cos(x)dx = \frac{1}{\pi}\int_{-\pi/2}^{\pi/2}\cos(x)dx = \frac{2}{\pi}$
$a_0 = \frac{1}{\pi}\int_{-\pi}^{\pi}\cos(x)dx = \frac{2}{\pi}\int_{-\pi/2}^{\pi/2}\cos(x)dx = \frac{4}{\pi}$
First of all, your equation
$$a_0 = \frac1\pi \int_{-\pi}^\pi \cos(x)dx$$
is incorrect. The correct equation is
$$a_0 = \frac1\pi \int_{-\pi}^\pi f(x)dx$$
and this is different, because the function $f(x)$ is not equal to $\cos(x)$ for all values $x\in[-\pi,\pi]$.
In general, if a function is integrable on $[a,b]$ and you have $a<c<b$, then $$\int_a^b f(x)dx = \int_a^c f(x)dx + \int_c^b f(x)dx$$
In your case, that means you have
$$\int_{-\pi}^\pi f(x)dx = \int_{-\pi}^{-\frac{\pi}{2}}f(x)dx + \int_{-\frac\pi2}^{\frac\pi2}f(x)dx+\int_{\frac\pi2}^\pi f(x)dx$$
and you should notice that two of the three summands simplify a lot :).