How can we evaluate the integral $\int_{0}^{\infty} \frac{d x}{1+x+x^{2}+\ldots+x^{n-1}}$, where $n\geq 3$? We are going to investigate the integral
$$
I_{n}=\int_{0}^{\infty} \frac{d x}{1+x+x^{2}+\ldots+x^{n-1}} \text {, where } n \geqslant 3.
$$
Let’s start with the simpler cases.
$$
\begin{aligned}
I_{3} &=\int_{0}^{\infty} \frac{d x}{1+x+x^{2}} \\
&=\int_{0}^{\infty} \frac{d x}{\left(x+\frac{1}{2}\right)^{2}+\left(\frac{\sqrt{3}}{2}\right)^{2}} \\
&=\frac{2}{\sqrt{3}}\left[\tan ^{-1}\left(\frac{2 x+1}{\sqrt{3}}\right)\right]_{0}^{\infty} \\
&=\frac{2}{\sqrt{3}}\left(\frac{\pi}{2}-\frac{\pi}{6}\right) \\
&=\frac{2 \pi}{3 \sqrt{3}}
\end{aligned}
$$
and
$$
\begin{aligned}
I_{4} &=\int_{0}^{\infty} \frac{1}{(1+x)\left(1+x^{2}\right)} d x \\
&=\frac{1}{2} \int_{0}^{\infty}\left(\frac{1}{x+1}+\frac{1-x}{x^{2}+1}\right) d x \\
&=\frac{1}{2}\left[\ln (x+1)+\tan ^{-1} x-\frac{1}{2} \ln \left(x^{2}+1\right)\right]_{0}^{\infty} \\
&=\frac{1}{4}\left[\ln \frac{(x+1)^{2}}{x^{2}+1}\right]_{0}^{\infty}+ \left[\frac{1}{2} \tan ^{-1} x\right]_{0}^{\infty} \\
&=\frac{\pi}{4}
\end{aligned}
$$
But the integrals are difficult when $n\geq 5$.
My question: Is there any elementary method to evaluate it?
Your suggestions and solutions are warmly welcome.
 A: Multiplying both numerator and denominator by $1-x$ converts the integral
$I_n:=\displaystyle \int_{0}^{\infty} \frac{1-x}{1-x^{n}} d x ,\textrm{ where }n\geq 3\tag*{} \\$
We shall evaluate the integral by the theorem
$ \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 2 integrals
$ \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} $,
we have
$$ \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*{} $$
Combining them and expanding the denominator into power series yields
$$ \begin{aligned} I_n&=\int_{0}^{1} \frac{1-x+x^{n-3}-x^{n-2}}{1-x^{n}} d x\\ &=\int_{0}^{1}\left[\left(1-x+x^{n-3}-x^{n-2}\right) \sum_{k=0}^{\infty} x^{n k}\right] d x\\ &=\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]\\ &=\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}$$
Recall the Theorem,
$\displaystyle  \sum_{k=-\infty}^{\infty} \frac{1}{k+z}=\pi \cot (\pi z), \tag*{} $
where $ z\notin Z.$
We can now conclude that
$\displaystyle \boxed{ I_n =\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}} \tag*{} $
By the way, is there any other elementary method?
A: You must have an error somewhere in the indices because
$$I_n=\int_0^\infty \frac{x-1}{x^{n+1}-1}\,dx = \frac{\pi  }{n+1}\csc \left(\frac{2 \pi }{n+1}\right)$$
There is another (but not elementary) method to find another form of the result using hypergeometric functions.
$$J_n=\int\frac{x-1}{x^{n+1}-1}\,dx =x \, _2F_1\left(1,\frac{1}{n+1};\frac{n+2}{n+1};x^{n+1}\right)-$$ $$\frac{1}{2} x^2 \,
   _2F_1\left(1,\frac{2}{n+1};\frac{n+3}{n+1};x^{n+1}\right)$$ which leads to
$$I_n=\cos \left(\frac{\pi }{n+1}\right) \Gamma \left(\frac{n}{n+1}\right) \Gamma
   \left(\frac{n+2}{n+1}\right)-$$ $$\frac{1}{2} \cos \left(\frac{2 \pi }{n+1}\right)
   \Gamma \left(\frac{n-1}{n+1}\right) \Gamma \left(\frac{n+3}{n+1}\right)$$
A: Too long for a comment
$$\int_{0}^{1} \Big(\frac{1-x}{1-x^{n}}+\frac{x^{n-3}-x^{n-2}}{1-x^{n}}\Big) dx=I_1+I_2$$
We can try to use the regularisation to get a shortcut to the answer. For example,
$$I_2=\int_{0}^{1} \frac{x^{n-3}-x^{n-2}}{1-x^{n}}dx=\lim_{\epsilon \to 0}\int_{0}^{1} (x^{n-3}-x^{n-2})(1-x^{n})^{\epsilon-1}dx$$
$$=\frac{1}{n}\lim_{\epsilon \to 0}\int_{0}^{1}(t^{-\frac{2}{n}}-t^{-\frac{1}{n}}) (1-t)^{\epsilon-1}dt$$
$$=\frac{1}{n}\lim_{\epsilon \to 0}\Gamma(\epsilon)\bigg(\frac{\Gamma(1-\frac{2}{n})}{\Gamma(1+\epsilon-\frac{2}{n})}-\frac{\Gamma(1-\frac{1}{n})}{\Gamma(1+\epsilon-\frac{1}{n})}\Bigg)$$
Given that $\Gamma(\epsilon)=\frac{1}{\epsilon}+O(1)$ and  $\Gamma(1+\epsilon-\frac{1}{n})=\Gamma(1-\frac{1}{n})+\Gamma(1-\frac{1}{n})\psi(1-\frac{1}{n})\,\epsilon +O(\epsilon^2)$, where $\psi(x)=\frac{\Gamma'(x)}{\Gamma(x)}$ - digamma-function
$$I_2=\frac{1}{n}\lim_{\epsilon \to 0}\frac{1}{\epsilon}\bigg(\frac{1}{1+\psi(1-\frac{2}{n})\,\epsilon}-\frac{1}{1+\psi(1-\frac{1}{n})\,\epsilon}\bigg)=\frac{1}{n}\Big(\psi(1-\frac{1}{n})-\psi(1-\frac{2}{n})\Big)$$
$$I_1+I_2=\frac{1}{n}\bigg(\psi\Big(\frac{2}{n}\Big)-\psi\Big(\frac{1}{n}\Big)+\psi\Big(1-\frac{1}{n}\Big)-\psi\Big(1-\frac{2}{n}\Big)\bigg)$$
Using $\psi(1-x)-\psi(x)=\pi\cot\pi x$, we immediately get
$$I_1+I_2=\frac{\pi}{n}\Big(\cot\frac{\pi}{n}-\cot\frac{2\pi}{n}\Big)$$
