<s>[INST] How to evaluate $\int 1/(1+x^{2n})\,dx$ for an arbitrary positive integer $n$? How to find
$$\int\dfrac{dx}{1+x^{2n}}$$
where $n \in \mathbb N$?
Remark
When $n=1$, the antiderivative is $\tan^{-1}x+C$. But already with $n=2$ this is something much more complicated. Is there a general method?
 [/INST] If the integral is taken from $0$ to $\infty$, there is more than one way to evaluate this. One is
$$
\begin{align}
\int_0^\infty\frac{\mathrm{d}t}{1+t^{2n}}
&=\int_0^1\frac{\mathrm{d}t}{1+t^{2n}}+\int_0^1\frac{t^{2n-2}\,\mathrm{d}t}{1+t^{2n}}\\
&=\int_0^1(1-t^{2n}+t^{4n}-t^{6n}+\dots)\,\mathrm{d}t\\
&+\int_0^1(t^{2n-2}-t^{4n-2}+t^{6n-2}+\dots)\,\mathrm{d}t\\
&=1-\frac{1}{2n+1}+\frac{1}{4n+1}-\frac{1}{6n+1}+\dots\\
&+\frac{1}{2n-1}-\frac{1}{4n-1}+\frac{1}{6n-1}-\dots\\
&=\frac{1}{2n}\left(\frac{1}{0+\frac{1}{2n}}-\frac{1}{1+\frac{1}{2n}}+\frac{1}{2+\frac{1}{2n}}-\frac{1}{3+\frac{1}{2n}}+\dots\right)\\
&+\frac{1}{2n}\left(-\frac{1}{-1+\frac{1}{2n}}+\frac{1}{-2+\frac{1}{2n}}-\frac{1}{-3+\frac{1}{2n}}-\dots\right)\\
&=\frac{1}{2n}\sum_{k=-\infty}^\infty\frac{(-1)^k}{k+\frac{1}{2n}}\\
&=\frac{\pi}{2n}\csc\left(\frac{\pi}{2n}\right)\tag{1}
\end{align}
$$
The last step uses the result from "An Infinite Alternating Harmonic Series" on this page.

Another method is to use contour integration to evaluate
$$
\frac12\int_{-\infty}^\infty\frac{\mathrm{d}t}{1+t^{2n}}
=\frac12\oint_\gamma\frac{\mathrm{d}z}{1+z^{2n}}\tag{2}
$$
where $\gamma$ is the path from $-\infty$ to $\infty$ along the real axis (which picks up the integral in question), then circling back counter-clockwise around the upper half-plane (which vanishes). The countour integral in $(2)$ is $2\pi i$ times the sum of the residues of $\frac{1}{1+z^{2n}}$ in the upper half-plane.
The poles of the integrand in $(2)$ are given by
$$
\zeta_k=e^{\frac{\pi i}{2n}(2k+1)}\tag{3}
$$
where $k=0\dots n-1$ represent the roots in the upper half-plane. All the poles are simple, so the residues are
$$
\begin{align}
\mathrm{Res}_{z=\zeta_k}\left(\frac{1}{1+z^{2n}}\right)
&=\lim_{z\to\zeta_k}\frac{z-\zeta_k}{1+z^{2n}}\\
&=-\frac{1}{2n}\zeta_{k}\\
&=-\frac{1}{2n}e^{\frac{\pi i}{2n}(2k+1)}\tag{4}
\end{align}
$$
Thus, we get
$$
\begin{align}
\int_0^\infty\frac{\mathrm{d}t}{1+t^{2n}}
&=-\frac{2\pi i}{4n}\sum_{k=0}^{n-1}e^{\frac{\pi i}{2n}(2k+1)}\\
&=-\frac{\pi i}{2n}e^{\frac{\pi i}{2n}}\frac{1-(-1)}{1-e^{\frac{\pi i}{n}}}\\
&=\frac{\pi}{2n}\csc\left(\frac{\pi}{2n}\right)\tag{5}
\end{align}
$$
</s>