Residue Integral: $\int_0^\infty \frac{x^n - 2x + 1}{x^{2n} - 1} \mathrm{d}x$

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

enter image description here

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.


Just in case someone wonders how it can be done the "normal" way, here it is.

By factorization what we are trying to prove is: $$ \int_0^\infty \frac{1}{x^n-1} dx = 2 \int_0^\infty \frac{x}{x^{2n}-1} dx $$ On the right hand side let $x \rightarrow \sqrt{t}$.