Integral $\int_0^\infty \frac{x^n - 2x + 1}{x^{2n} - 1} \mathrm{d}x=0$ Inspired by some of the greats on this site, I've been trying to improve my residue skills. I've come across the integral
$$\int_0^\infty \frac{x^n - 2x + 1}{x^{2n} - 1} \mathrm{d}x=0$$
where $n$ is a positive integer that is at least $2$.
With non-complex methods, I know that the integral is $0$. But I know that it can be done with residue theorem.
The trouble comes in choosing a contour. We're probably going to do some pie-slice contour, perhaps small enough to avoid any of the $2n$th roots of unity, and it's clear that the outer-circle vanishes. But I'm having trouble getting the cancellation for the integral.
Can you help? (Also, do you have a book reference for collections of calculations of integrals with the residue theorem that might have similar examples?)

We want to prove that the integral is $0$ for $n>1$, it is the same thing as 
$$\int_0^{\infty} \frac{\mathrm{d}x}{x^n+1} = 2\int_0^{\infty} \frac{x-1}{x^{2n}-1} \ \mathrm{d}x.$$
The left hand integral is widely known to be $\frac{\pi}{n} \csc \frac{\pi}{n}$, we want to calculate the right hand integral. let $f(x)=\frac{x-1}{x^{2n}-1}$, and consider the contour $C=C_1\cup C_2\cup C_3$ where $$C_1=[0,r],\ C_2=\left\{z \in \mathbb{C} | |z|=r,\ \arg(z) \in \left[0,\frac{\pi}{2n}\right]\right\},\ \ C_3 =e^{\frac{\pi i}{2n}} C_1. $$
Here's what the contour look like  

Notice that $\int_C f(z) \ \mathrm{d}z=0$ (the integral is taken counter clockwise always) since $f$ is holomorphic inside $C$. and 
$$\left|\int_{C_2} f(x)\ \mathrm{d}x \right| =\mathcal{O}(r^{-1}) \to 0.$$
And 
\begin{align*}
\int_{C_3}f(z) \ \mathrm{d}z &= e^{\frac{\pi i}{2n}}\int_0^r f\left(x e^{\frac{\pi i }{2n}}\right) \ \mathrm{d}x \\ 
&=e^{\frac{\pi i}{2n}}\int_0^r \frac{e^{\frac{\pi i}{2n}}x -1}{x^{2n}+1} \ \mathrm{d}x \\ 
&= e^{\frac{\pi i}{n}}\int_0^r \frac{x }{x^{2n}+1} \ \mathrm{d}x-e^{\frac{\pi i}{2n}}\int_0^r \frac{1}{x^{2n}+1} \ \mathrm{d}x.
\end{align*}
Note that $\int_{0}^{\infty} \frac{x}{x^{2n}+1} \ \mathrm{d}x  = \frac{\pi }{2n} \csc \frac{\pi}{n}$, then by taking $r\to \infty$ we get 
$$\int_0^{\infty} f(x) \  \mathrm{d}x =-e^{\frac{\pi i}{n}}\cdot \frac{\pi }{2n} \csc \frac{\pi}{n} + e^{\frac{\pi i}{2n}} \frac{\pi }{2n} \csc \frac{\pi}{2n} = \frac{\pi}{2n} \csc \frac{\pi}{n}.$$ 
Which is what we were looking for.
