Help in calculating the following integral $\int_0^{2\pi}\! \frac{(1+2\cos x)^n \cos (nx)}{3+2\cos x} \, \mathrm{d}x. $ I was asked to calculate this:

$$\int_0^{2\pi}\! \frac{(1+2\cos x)^n \cos (nx)}{3+2\cos x} \, \mathrm{d}x. $$

My idea was to change the integration limits to $|z|=1$ in the complex plane and to use the residue theorem:
$$\int\limits_{|z|=1}\!\frac{(1+z+z^{-1})^n\frac{1}{2}(z^n+z^{-n})}{3+z+z^{-1}} \,\frac{\mathrm{d}z}{iz} = -\frac{i}{2} \int\limits_{|z|=1}\!\frac{(z^2+z+1)^n(z^{2n}+1)}{z^{2n}(z^2+3z+1)} \,\mathrm{d}z$$
but this requires me to calculate $$\lim_{z \to 0}\frac{d^{2n-1}}{dz^{2n-1}}\left[\frac{(z^2+z+1)^n(z^{2n}+1)}{z^2+3z+1}\right]$$ in order to get the residue at $z=0$. Is there any other way of doing this?
 A: $$ \begin{align} \int_{0}^{2 \pi} \frac{(1+2 \cos x)^{n} \cos (nx)}{3 + 2 \cos x} \ dx &= \text{Re} \int_{0}^{2 \pi} \frac{(1+2 \cos x)^{n} e^{inx}}{3 + 2 \cos x} \ dx \\ &= \text{Re} \int_{0}^{2 \pi}\frac{(1+ e^{ix} + e^{-ix})^{n}e^{inx}}{3 + e^{ix} + e^{-ix}} \ dx \\ &= \text{Re} \int_{|z|=1} \frac{(1+z+z^{-1})^{n}z^{n}}{3+z+z^{-1}} \frac{dz}{iz} \\ &= \text{Re} \frac{1}{i} \int_{|z|=1} \frac{(z^{2}+z+1)^{n}}{z^{2}+3z+1} \ dz \\ &= \text{Re} \frac{1}{i} \int_{|z|=1} \frac{(z^{2}+z+1)^{n}}{(z+ \frac{3}{2} - \frac{\sqrt{5}}{2})(z+ \frac{3}{2} + \frac{\sqrt{5}}{2})} \ dz\end{align}$$
Only the pole at $z= - \frac{3}{2} + \frac{\sqrt{5}}{2}$ is inside of the unit circle.
Therefore,
$$ \begin{align} \int_{0}^{2 \pi} \frac{(1+2 \cos x)^{n} \cos (nx)}{3 + 2 \cos x} \ dx &= \text{Re} \frac{1}{i} 2 \pi i \ \text{Res} \Big[\frac{(z^{2}+z+1)^{n}}{z^{2}+3z+1}, - \frac{3}{2} + \frac{\sqrt{5}}{2}\Big] \\ &= 2 \pi \ \text{Re} \lim_{z \to - \frac{3}{2} + \frac{\sqrt{5}}{2}} \frac{(z^{2}+z+1)^{n}}{z+ \frac{3}{2} + \frac{\sqrt{5}}{2}} \\ &= 2 \pi \ \text{Re} \frac{(\frac{7}{2} - \frac{3 \sqrt{5}}{2} - \frac{3}{2} + \frac{\sqrt{5}}{2} +1)^{n}}{\sqrt{5}} \\ &= 2 \pi \frac{(3-\sqrt{5})^{n}}{\sqrt{5}} \end{align}$$
