How to evaluate this improper integral $\int_{0}^{\infty}\frac{1-x}{1-x^{n}}\,\mathrm dx$? 
$\def\d{\mathrm{d}}$How to evaluate this improper integral? 
  $$\int_{0}^{\infty}\frac{1-x}{1-x^{n}}\,\d x.$$

What I tried is a substitution i.e $x^{n}=t$, but then things got complicated, and I'm stuck.
 A: Here are two methods,using real analysis
Method : 1 : using some special functions :
$$I=\displaystyle \int_{0}^{\infty}\dfrac{1-x}{1-x^{n}}\,dx=\underbrace{\displaystyle \int_{0}^{1}\dfrac{1-x}{1-x^{n}}\,dx}_{I_{1}(n)}+\underbrace{\displaystyle \int_{1}^{\infty}\dfrac{1-x}{1-x^{n}}\,dx}_{I_{2}(n)} $$
$$I_{1}(n)=\displaystyle \int_{0}^{1}\dfrac{1-x}{1-x^{n}}\,dx$$
Now lets make a substitution , $x^{n}=t \implies dx=\dfrac{1}{n}t^{\frac{1}{n}-1}dt$ , so $I_{1}(n)$ becomes
$$I_{1}(n)=\dfrac{1}{n}\displaystyle \int_{0}^{1}\dfrac{1-t^{\frac{1}{n}}}{1-t}.t^{\frac{1}{n}-1}\,dt= \dfrac{1}{n}\left[\displaystyle 
\int_{0}^{1}\dfrac{t^{\frac{1}{n}-1}}{1-t}\,dt-\displaystyle \int_{0}^{1}\dfrac{{t^{\frac{2}{n}-1}}}{1-t}\,dt \right]$$
$$I_{1}(n)= \dfrac{1}{n}\displaystyle \lim_{m \rightarrow 0}\left[ \beta\left(m,\dfrac{1}{n}\right)-\beta \left(m,\dfrac{2}
{n}\right)\right] $$
$$\large \boxed{I_{1}(n)=\dfrac{1}{n} \left[\psi\left(\dfrac{2}{n}\right)-\psi \left(\dfrac{1}{n}\right)\right]}$$
now lets take $I_{2}(n)$
$$I_{2}(n)=\displaystyle \int_{1}^{\infty}\dfrac{1-x}{1-x^{n}}\,dx$$
Now for this one substitute $x=\dfrac{1}{t} \implies dx=-\dfrac{1}{t^{2}} dt$
$$I_{2}(n)=\displaystyle \int_{0}^{1}\dfrac{1-t}{1-t^{n}}t^{n-3}\,dt$$
Now make another substitution $t^{n}=u \implies dt=\dfrac{1}{n}u^{\frac{1}{n}-1}du$ , so the integral becomes
$$I_{2}(n)=\dfrac{1}{n}\displaystyle \int_{0}^{1}\dfrac{1-u^{\frac{1}{n}}}{1-u}\left(u^{\frac{1}{n}-1}\right)\left(u^{1-\frac{3}{n}}\right)\,du$$
$$I_{2}(n)= \dfrac{1}{n}\left[\displaystyle \int_{0}^{1}\dfrac{u^{-\frac{2}{n}}}{1-u}\,du-\displaystyle \int_{0}^{1}\dfrac{{u^{-\frac{1}{n}}}}{1-u}\,du \right]$$
$$I_{2}(n)= \dfrac{1}{n}\displaystyle \lim_{m \rightarrow 0}\left[ \beta\left(m,1-\dfrac{2}{n}\right)-\beta \left(m,1-\dfrac{1}{n}\right)\right]$$
$$\large \boxed{I_{2}(n)= \dfrac{1}{n}\left[ \psi\left(1-\dfrac{1}{n}\right)-\psi \left(1-\dfrac{2}{n}\right)\right]}$$
Now we just have to add $I_{1}(n)$ and $I_{2}(n)$
$$\begin{equation} I(n)=\dfrac{1}{n}\left[ -\psi\left(\dfrac{1}{n}\right)+\psi\left(1-\dfrac{1}{n}\right)+\psi\left(\dfrac{2}{n}\right)-
\psi \left(1-\dfrac{2}{n}\right)\right]\\= \dfrac{\pi}{n}\left[ \cot \left(\dfrac{\pi}{n}\right)-\cot \left(\dfrac{2\pi}{n}\right)\right]\\=
\dfrac{\pi}{n}\csc\left(\dfrac{2 \pi}{n}\right)\end{equation}$$
$$\Large \displaystyle\ \bbox[10pt, border:2pt solid #06f]{I(n)=\dfrac{\pi}{n}\csc\left(\dfrac{2 \pi}{n}\right)} \tag*{}$$
hete $\psi\Rightarrow $Digamma function and $\beta\Rightarrow $Beta function.
and the reflection formula i used to simplify is known as Euler’s reflection formula which is …
$$\boxed{\psi(1-z)-\psi(z)=\pi \cot(\pi z)} $$
Method : 2 : Mellin Transform:
$$I(n)=\displaystyle \int_{0}^{\infty}\dfrac{1-x}{1-x^{n}}\,dx$$
so lets use the same substitution again ..
$x^{n}=t \implies dx=\dfrac{1}{n}t^{\frac{1}{n}-1}dt $ so the integral becomes
$$I(n)=\dfrac{1}{n} \displaystyle \int_{0}^{\infty}\dfrac{1-t^{\frac{1}{n}}}{1-t}t^{\frac{1}{n}-1}\,dt$$
$$I(n)=\dfrac{1}{n}\left[\underbrace{\displaystyle \int_{0}^{\infty}\dfrac{t^{\frac{1}{n}-1}}{1-t}\,dt}_{F_{1}(t)}- \underbrace
{\displaystyle \int_{0}^{\infty}\dfrac{t^{\frac{2}{n}-1}}{1-t}\,dt}_{F_{2}(t)}\right]$$
So again we have two separate integrals , now using melling transform we can evaluate these two very easily , so first lets define the
standard Mellin transform of a function let's say $f(t)$ , it is given by ..
$$\mathcal{M}[f(t)]=F(s)=\displaystyle \int_{0}^{\infty}f(t)t^{s-1}dt$$
So, now if we compare $F_{1}(t)$ with the above integral then we can see that ..
$s_{1}=\dfrac{1}{n}$ and $f_{1}(t)=\dfrac{1}{1-t}$
Now Mellin transform of $f_{1}(t)$ is well known, it is ...
$$\mathcal{M}[f_{1}(t)]\bigg{|}_{s_{1}=1/n}=\pi \cot(\pi s)\bigg{|}_{s=s_{1}}=\pi \cot\left(\dfrac{\pi}{n}\right),0<Re(s)<1 $$
and for $f_{2}(t)$ at $s_{2}=\dfrac{2}{n}$ it will be
$$\mathcal{M}[f_{2}(t)]\bigg{|}_{s_{2}=2/n}=\pi \cot(\pi s)\bigg{|}_{s=s_{2}}=\pi \cot\left(\dfrac{2\pi}{n}\right),0<Re(s)<1$$
$$I(n)=\dfrac{1}{n} \left[\mathcal{M}[f_{1}(t)]\bigg{|}_{s_{1}=2/n}- \mathcal{M}[f_{2}(t)]\bigg{|}_{s_{2}=2/n} \right]$$
$$I(n)=\dfrac{\pi}{n} \left[\cot\left(\dfrac{\pi}{n}\right)-\cot\left(\dfrac{2\pi}{n}\right)\right]$$
So, again we arrive at the same result i.e
$$\Large \displaystyle\ \bbox[10pt, border:2pt solid #06f]{I(n)=\dfrac{\pi}{n}\csc\left(\dfrac{2 \pi}{n}\right)} \tag*{}$$
A: I am going to assume that $n\in\{3,4,5,6,\ldots\}$. By splitting the integration range as $(0,1)\cup(1,+\infty)$ and applying the substitution $z\mapsto\frac{1}{z}$ on the second interval, we get that
$$ I_n=\int_{0}^{+\infty}\frac{1-z}{1-z^n}\,dz = \int_{0}^{1}\frac{z^{n-3}-z^{n-2}+1-z}{1-z^n}\,dz =\int_{0}^{1}\frac{(1-z)(z^3+z^n)}{1-z^n}\,dz$$
and by performing the substitution $z=u^{1/n}$ it follows that
$$ I_n = \frac{1}{n}\int_{0}^{1}\frac{(1-u^{1/n})(u^{3/n}+u)u^{1/n-1}}{1-u}\,du $$
where the perturbated integral
$$ I_n^\varepsilon = \frac{1}{n}\int_{0}^{1}\frac{(1-u^{1/n})(u^{3/n}+u)u^{1/n-1}}{(1-u)^{1-\varepsilon}}\,du $$
can be computed in terms of the $\Gamma$ function due to the integral representation for the Beta function, for any $\varepsilon>0$. By considering the limit as $\varepsilon\to 0^+$ we get an expression involving different values of the $\psi$ function, that by the reflection formula for the $\psi$ function simplifies to

$$ I_n = \color{red}{\frac{\pi}{n\sin\frac{2\pi}{n}}}.$$

A: We are going to evaluate the integral
$I:=\displaystyle \int_{0}^{\infty} \frac{1-x}{1-x^{n}} d x \tag*{} $
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
$$\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  I&=\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\\\displaystyle  & =\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)\\\displaystyle & =\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]\\ \displaystyle & =\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)\\\displaystyle & =\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}$$
By 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 =\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*{} $
