<s>[INST] Is there any other simpler method to evaluate $\int_0^{\infty} \frac{x^n-2 x+1}{x^{2 n}-1} d x,$ where $n\geq 2?$ Though $n\geq 2$ is a real number, which is not necessarily an integer, we can still resolve the integrand into two fractions,
$$\displaystyle I=\int_0^{\infty} \frac{x^n-2 x+1}{\left(1+x^n\right)\left(1-x^n\right)} d x=\int_0^{\infty}\left(\frac{x}{1+x^n}-\frac{1-x}{1-x^n}\right) d x=J-K\tag*{} $$
For the integral $J$, we are going to transforms it into a Beta function by letting $y=\frac{1}{1+x^n}$.
$$\displaystyle \begin{aligned}J & =\frac{1}{n} \int_0^1 y^{-\frac{2}{n}}(1-y)^{\frac{2}{n}-1} d y \\& =\frac{1}{n} B\left(-\frac{2}{n}+1, \frac{2}{n}\right) \\& =\frac{\pi}{n} \csc \left(\frac{2 \pi}{n}\right) \quad \textrm{ (By Euler Reflection Formula)}\end{aligned}\tag*{} $$

Next, we are going to evaluate the integral
$ \displaystyle K=\displaystyle \int_{0}^{\infty} \frac{1-x}{1-x^{n}} d x \tag*{} $
by the theorem
$ \displaystyle \displaystyle \sum_{k=-\infty}^{\infty} \frac{1}{k+z}=\pi \cot (\pi z), \textrm{ where } z\notin Z.\tag*{} $
We first split the integral into two integrals
$$ \displaystyle \displaystyle \int_{0}^{\infty} \frac{1-x}{1-x^{n}} d x=\int_{0}^{1} \frac{1-x}{1-x^{n}} d x+\int_{1}^{\infty} \frac{1-x}{1-x^{n}} d x \tag*{}$$
Transforming the latter integral by the inverse substitution $ x\mapsto \frac{1}{x}$ m, we have
$$\displaystyle \displaystyle \int_{1}^{\infty} \frac{1-x}{1-x^{n}} d x=\int_{0}^{1} \frac{x^{n-3}-x^{n-2}}{1-x^{n}} d x \tag*{}  $$
Putting back yields
$ \begin{aligned}\displaystyle K&=\int_{0}^{1} \frac{1-x+x^{n-3}-x^{n-2}}{1-x^{n}} d x\\\displaystyle &=\int_{0}^{1}\left[\left(1-x+x^{n-3}-x^{n-2}\right) \sum_{k=0}^{\infty} x^{n k}\right] d x\\ \displaystyle & =\sum_{k=0}^{\infty} \int_{0}^{1}\left[x^{n k}-x^{n k+1}+x^{n(k+1)-3}-x^{n(k+1)-2}\right] d x\\ & =\sum_{k=0}^{\infty}\left(\frac{1}{n k+1}-\frac{1}{n k+2}+\frac{1}{n(k+1)-2}-\frac{1}{n(k+1)-1}\right)\\ & =\sum_{k=0}^{\infty}\left[\frac{1}{n k+1}-\frac{1}{n(k+1)-1}\right]+\sum_{k=0}^{\infty}\left[\frac{1}{n(k+1)-2}-\frac{1}{n k+2}\right] \end{aligned}\tag*{} $
Modifying yields
$$\displaystyle \begin{aligned} K&=\frac{1}{n}\left[\sum_{k=0}^{\infty} \frac{1}{k+\frac{1}{n}}+\sum_{k=-1}^{-\infty} \frac{1}{k+\frac{1}{n}}\right]+\frac{1}{n}\left(\sum_{k=1}^{\infty} \frac{1}{k-\frac{2}{n}}+\sum_{k=0}^{-\infty} \frac{1}{k-\frac{2}{n}}\right)\\& =\frac{1}{n}\left(\sum_{k=-\infty}^{\infty} \frac{1}{k+\frac{1}{n}}+\sum_{k=-\infty}^{\infty} \frac{1}{k-\frac{2}{n}}\right)\end{aligned} \tag*{} $$
By the Theorem,
$$ \displaystyle \displaystyle \sum_{k=-\infty}^{\infty} \frac{1}{k+z}=\pi \cot (\pi z), \tag*{} $$
where $ \displaystyle z\notin Z,$
we have
$$ \displaystyle \displaystyle K=\frac{1}{n}\left[\pi \cot \left(\frac{\pi}{n}\right)+\pi \cot \left(\frac{-2 \pi}{n}\right)\right]=\frac{\pi}{n}\left[\cot \left(\frac{\pi}{n}\right)-\cot \left(\frac{2 \pi}{n}\right)\right] =\frac{\pi}{n} \csc \frac{2 \pi}{n} =J\tag*{} $$

We can now conclude that
$\displaystyle \boxed{I=J-K=0 }\tag*{} $

Is there any other simpler method to evaluate $\int_0^{\infty} \frac{x^n-2 x+1}{x^{2 n}-1} d x,$ where $n\geq 2?$
 [/INST] We have
\begin{align*}
&\int_{0}^{\infty} \frac{x^n - 2x + 1}{x^{2n} - 1} \, \mathrm{d}x \\
&= \int_{0}^{\infty} \left( \frac{1}{x^n - 1} - \frac{2x}{x^{2n} - 1} \right) \, \mathrm{d}x \\
&= \mathrm{PV}\!\int_{0}^{\infty} \frac{1}{x^{n} - 1} \, \mathrm{d}x - \mathrm{PV}\!\int_{0}^{\infty} \frac{2x}{x^{2n} - 1} \, \mathrm{d}x \\
&= \mathrm{PV}\!\int_{0}^{\infty} \frac{1}{x^{n} - 1} \, \mathrm{d}x - \mathrm{PV}\!\int_{0}^{\infty} \frac{1}{u^{n} - 1} \, \mathrm{d}u \tag{$u = x^2$} \\
&= 0.
\end{align*}

Addendum. Here, we rigorously justify the third step. Expanding the principal value using the definition,
\begin{align*}
&\mathrm{PV}\!\int_{0}^{\infty} \frac{2x}{x^{2n} - 1} \, \mathrm{d}x \\
&= \lim_{\varepsilon \to 0^+} \int_{[0, 1-\varepsilon]\cup[1+\varepsilon,\infty)} \frac{2x}{x^{2n} - 1} \, \mathrm{d}x \\
&= \lim_{\varepsilon \to 0^+} \int_{[0, (1-\varepsilon)^2]\cup[(1+\varepsilon)^2,\infty)} \frac{1}{u^n - 1} \, \mathrm{d}u .\tag{$u = x^2$}
\end{align*}
Then the last integral is recast as
\begin{align*}
&\int_{[0, (1-\varepsilon)^2]\cup[(1+\varepsilon)^2,\infty)} \frac{1}{u^n - 1} \, \mathrm{d}u \\
&= \int_{[0, 1-2\varepsilon]\cup[1+2\varepsilon,\infty)} \frac{1}{u^n - 1} \, \mathrm{d}u
+ \int_{1-2\varepsilon}^{(1-\varepsilon)^2} \frac{1}{u^n - 1} \, \mathrm{d}u 
- \int_{1+2\varepsilon}^{(1+\varepsilon)^2} \frac{1}{u^n - 1} \, \mathrm{d}u
\end{align*}
The first integral converges to the desired term $\mathrm{PV}\!\int_{0}^{\infty} \frac{1}{u^n - 1} \, \mathrm{d}u$, hence it suffices to prove that the remaining two integrals vanish as $\varepsilon \to 0^+$. However,
\begin{align*}
\int_{1-2\varepsilon}^{(1-\varepsilon)^2} \frac{1}{\left| u^n - 1 \right|} \, \mathrm{d}u
\leq \int_{1-2\varepsilon}^{(1-\varepsilon)^2} \mathcal{O}(\varepsilon^{-1}) \, \mathrm{d}u
\leq \mathcal{O}(\varepsilon)
\end{align*}
and similarly,
\begin{align*}
\int_{1+2\varepsilon}^{(1+\varepsilon)^2} \frac{1}{\left| u^n - 1 \right|} \, \mathrm{d}u
\int_{1+2\varepsilon}^{(1+\varepsilon)^2} \mathcal{O}(\varepsilon^{-1}) \, \mathrm{d}u
\leq \mathcal{O}(\varepsilon).
\end{align*}
Therefore both integrals vanish as $\varepsilon \to 0^+$ and hence the desired claim follows.
</s>