Is it possible to calculate $\int_{0}^{\pi}(a+\cos{\theta})^nd\theta$, where $a$ is a nonzero integer? I have tried to answer by taking change the variable $\theta$ to $\theta/2$, so the integration is now over unit circle, then I have taken $z=e^{i\theta}$. Now I tried to use residue formula for integration, but I failed.

$\int_0^{\pi} (a+\cos x)^n \ dx = \frac 12 \int_0^{2\pi} (a+\cos x)^n \ dx\\
\cos x = \frac 12 (e^{ix} + e^{-ix})\\
\frac 1{2^{n+1}} \int_0^{2\pi} (2a+e^{ix} + e^{-ix})^n \ dx
z = e^{ix}\\
dx = \frac {1}{iz}\ dz$
$\frac 1{2^{n+1}i} \oint_{|z| = 1} \frac {1}{z}(2a+z + z^{-1})^n \ dz$
Now the trick.  When we expand $(2a+z + z^{-1})^n$ we only care about the constant term.  The rest of the terms will evaluate to $0.$
$(2a+z + z^{-1})^n = \sum_\limits{k=0}^n {n\choose k} (z+z^{-1})^k(2a)^{n-k}$
There is only a constant term for $(z+z^{-1})^k$ if $k$ is even, and it will equal ${k\choose \frac{k}{2}}$
$\frac{\pi}{2^n}\sum_\limits{k=0}^{\lfloor \frac n2\rfloor} {n\choose 2k}{2k\choose k}(2a)^{n-2k}$
