Solution.
Let f(z)=z2+1zp and for 0<ε<1<R, consider the contour γε,R given by
γε,R=[−R,−ε]∪{εeiθ∣0≤θ≤π}∪[ε,R]∪{Reiθ∣0≤θ≤R}.
On the larger semicircle CR,
∣∣∫CRf(z)dz∣∣≤∫0π∣∣R2ei2θ+1iRp+1eipθeiθ∣∣dθ≤Rp+1∫0πR2−11dθ=R2−12πRp+1R→∞0,
since ∣p+1∣<2. On the smaller semicircle Cε,
∣∣∫Cεf(z)dz∣∣≤∫0π∣∣ε2ei2θ+1iεp+1eipθeiθ∣∣dθ≤εp+1∫0πε2−11dθ=ε2−12πεp+1ε→∞0,
since ∣ε∣<1, so the denominator is non-zero. On [−R,−ε], taking arguments in (−2π,23π), we have
∫−R−εz2+1zpdz=∫−R−εz2+1eplogzdz=∫−R−εx2+1ep(logx+iπ)dz=eipπ∫−R−εx2+1xpdx.
Next, by the residue theorem,
∫γε,Rf(z)dz=2πiRes(f;i)=2πiz→ilim(z−i)z2+1zp=2πiz→ilimz+izp=πeipπ/2.
Thus, in the limit as ε→0 and R→∞,
(1+eipπ)∫0∞x2+1xpdx=πeipπ/2.
To complete the computation, we compute
1+eipπeipπ/2⟹∫0∞x2+1xpdx=e−ipπ/2+eipπ/21=2cos2pπ1=2πsec2pπ.