<s>[INST] Evaluate $\int _0^{2\pi }\frac{\cos (n\theta) }{a+\cos\theta}\,d\theta$ with $a>1$, $n\in \mathbb{N}-\left\{0\right\}$ 
Evaluate $$\int _0^{2\pi }\frac{\cos (n\theta) }{a+\cos\theta}\,d\theta,\quad\,a>1$$

I wrote $$f\left(z\right)=\frac{\frac{1}{2}\left(z^n+z^{-n}\right)}{\frac{iz^2}{2}+aiz+\frac{i}{2}}$$
The discriminant is $\Delta =a^2-1>0$
Poles are $z=-a\pm \sqrt{a^2-1}$ and $z=0$
$z=-a+\sqrt{a^2-1}$ and $z=0$ are within the unit circle.
Applying the residue theorem, we compute: $2i\pi \lim _{z\to -a+\sqrt{a^2-1}}\left(\frac{-\frac{i}{2}\left(z^n+z^{-n}\right)}{\frac{1}{2}\left(z+a+\sqrt{a^2-1}\right)}\right)$
The first residue is $\pi \frac{\left(-a+\sqrt{a^2-1}\right)^n+\left(-a+\sqrt{a^2-1}\right)^{-n}}{\sqrt{a^2-1}}$
Now $2i\pi \lim _{z\to 0}\left(\frac{-\frac{i}{2}\left(z^{n+1}+z^{-n+1}\right)}{\frac{1}{2}\left(z+a-\sqrt{a^2-1}\right)\left(z+a+\sqrt{a^2-1}\right)}\right)$ $=\lim _{z\to 0}\left(2\pi \left(z^{n+1}+z^{-n+1}\right)\right)\:$
 [/INST] As cosine is an even function, integral from o to 2$\pi$ can be written as 2 times the the integral from 0 to $\pi$, So you would be left with the upper semicircle and hence take $\frac{-ai + i \sqrt{a^2 -1}}{2}$. This is because in the upper plane imaginary part $Im(z) >= 0$.
</s>