[] Kloosterman’s formula is given by [titch, p. 25, Equation (2.9.2)]
\begin{aligned}
\psi(x+1)-\log(x)=\frac{1}{2\pi i}\int_{(c)}\frac{-\pi\zeta(1-z)}{\sin(\pi z)}x^{-z}dz,
\end{aligned}
which is valid for 0<c=\mathrm{Re}(z)<1. An application of the functional equation
\begin{aligned}
\psi(x+1)=\psi(x)+1/x
\end{aligned}
in (Proof) implies that
\begin{aligned}
\psi(x)-\log(x)+\frac{1}{x}=\frac{1}{2\pi i}\int_{(c)}\frac{-\pi\zeta(1-z)}{\sin(\pi z)}x^{-z}dz.
\end{aligned}
For our purpose we need the integral representation for the function \psi(x)-\log(x)+\frac{1}{2x}. For that, we shift the line of the integration to 1<d=\mathrm{Re}(z)<2. Let \mathfrak{C} be a positively oriented rectangular contour formed by the points c-iT, d-iT, d+iT, c+iT. Observe that the integrand has only one simple pole at s=1 due to \sin(\pi z) and its residue is -1/(2x) as \zeta(0)=-1/2. Therefore, residue theorem immediately yields
\begin{aligned}
\frac{1}{2\pi i}\left(\int_{d-iT}^{d+iT}+\int_{d+iT}^{c+iT}-\int_{c-iT}^{c+iT}+\int_{c-iT}^{d-iT}\right)\frac{-\pi\zeta(1-z)}{\sin(\pi z)}x^{-z}dz=-\frac{1}{2x}.
\end{aligned}
Note that the integrals along the horizontal lines goes to zero by using the Stirling formula in the vertical strip p\leq\sigma\leq q [cop, p. 224]:
|\Gamma(s)|=\sqrt{2\pi}|t|^{\sigma-\frac{1}{2}}e^{-\frac{1}{2}\pi |t|}\left(1+O\left(\frac{1}{|t|}\right)\right)
as |t|\to \infty. Thus, from (Proof), we have
\begin{aligned}
\frac{1}{2\pi i}\int_{(d)}\frac{-\pi\zeta(1-z)}{\sin(\pi z)}x^{-z}dz=\frac{1}{2\pi i}\int_{(c)}\frac{-\pi\zeta(1-z)}{\sin(\pi z)}x^{-z}dz-\frac{1}{2x}.
\end{aligned}
Combining (Proof) and (Proof) together, we obtain
\begin{aligned}
\psi(x)-\log(x)+\frac{1}{2x}=\frac{1}{2\pi i}\int_{(d)}\frac{-\pi\zeta(1-z)}{\sin(\pi z)}x^{-z}dz.
\end{aligned}
Replacing x by n^Nx in the above equation and invoking (?), we obtain
\begin{aligned}
\mathfrak{F}_{k,N}(x)&=\sum_{n=1}^\infty\frac{1}{n^k}\frac{1}{2\pi i}\int_{(d)}\frac{-\pi\zeta(1-z)}{\sin(\pi z)}(n^Nx)^{-z}dz\\
&=\frac{1}{2\pi i}\int_{(d)}\frac{-\pi\zeta(1-z)\zeta(k+Nz)}{\sin(\pi z)}x^{-z}dz,
\end{aligned}
where in the last step we interchanged the order of the summation and integration and used the series definition of \zeta(s). We now make change of variable s=1-k-Nz in (Proof) to deduce, for 1-k-2N<c<1-k-N,
\begin{aligned}
\mathfrak{F}_{k,N}(x)&=\frac{x^{\frac{k-1}{N}}}{N}\frac{1}{2\pi i}\int_{(c)}\frac{-\pi\zeta\left(1+\frac{s+k-1}{N}\right)\zeta(1-s)}{\sin\left(\frac{\pi}{N}(1-s-k)\right)}x^{\frac{s}{N}}ds
\end{aligned}
We next shift the line of integration to 1<\lambda<2. Consider the contour formed by the line segments [\lambda-iT,\lambda+iT],\ [\lambda+iT,c+iT],\ [c+iT,c-iT] and [c-iT,\lambda-iT]. In order to do so, we encounter several poles of different orders depending upon k and N. We denote the sum of the residues by \mathscr{R}_{k,N}(x). By invoking Stirling’s formula (Proof), we see that the integrals along the horizontal lines vanish as T\to\infty. Thus, by residue theorem and (Proof), we have
\begin{aligned}
\mathfrak{F}_{k,N}(x)&=\frac{x^{\frac{k-1}{N}}}{N}\left(\frac{1}{2\pi i}\int_{(\lambda)}\frac{\pi\zeta\left(1+\frac{s+k-1}{N}\right)\zeta(1-s)}{\sin\left(\frac{\pi}{N}(s+k-1)\right)}x^{\frac{s}{N}}ds-\mathscr{R}_{k,N}(x)\right).
\end{aligned}
Now, the main task is to evaluate the line integral present on the right-hand side of the above equation. Let us denote it by \mathcal{I}_{k,N}(x). To that end, we invoke following result [dgkm, Lemma 4.1]
\begin{aligned}
\frac{1}{\sin(z)}=\frac{1}{\sin(Nz)}\sideset{}{''}\sum_{j=-(N-1)}^{N-1}e^{ijz}
\end{aligned}
with z=\frac{\pi}{N}(s+k-1) in \mathcal{I}_{k,N}(x), so that
\begin{aligned}
\mathcal{I}_{k,N}(x)=\sum_{j=-(N-1)}^{(N-1)}{\vphantom{\sum}}''e^{\frac{i\pi j (k-1)}{N}}\frac{1}{2\pi i}\int_{(\lambda)}\frac{\pi\zeta(1-s)\zeta\left(1+\frac{s+k-1}{N}\right)}{\sin \left(\pi(s+k-1) \right)}\left(\frac{e^{-\frac{i\pi j}{N}}}{x^{1/N}}\right)^{-s}.
\end{aligned}
We can use the series definition of \zeta\left(1+\frac{s+k-1}{N}\right) since 1<\lambda=\mathrm{Re}(s)<2. Thus, we arrive at
\begin{aligned}
\mathcal{I}_{k,N}(x)=(-1)^{k}\sum_{j=-(N-1)}^{(N-1)}{\vphantom{\sum}}''e^{\frac{i\pi j (k-1)}{N}}\sum_{n=1}^{\infty}\frac{1}{n^{1+\frac{k-1}{N}}}\frac{1}{2\pi i}\int_{(\lambda)}\frac{-\pi\zeta(1-s)}{\sin \left(\pi s\right)} \left(\left(\frac{n}{x}\right)^{\frac{1}{N}}e^{-\frac{i\pi j}{N}}\right)^{-s}ds.
\end{aligned}
Invoking (Proof) in the above equation so as to obtain
\begin{aligned}
\mathcal{I}_{k,N}(x)&=(-1)^{k}\sum_{j=-(N-1)}^{(N-1)}{\vphantom{\sum}}''e^{\frac{i\pi j (k-1)}{N}}\sum_{n=1}^{\infty}\frac{1}{n^{1+\frac{k-1}{N}}}\left\{\psi\left(\left(\frac{n}{x}\right)^{\frac{1}{N}}e^{-\frac{i\pi j}{N}}\right)-\log\left(\left(\frac{n}{x}\right)^{\frac{1}{N}}e^{-\frac{i\pi j}{N}}\right)\right.\\
&\left.\qquad\qquad\qquad+\frac{1}{2}\left(\frac{n}{x}\right)^{-\frac{1}{N}}e^{\frac{i\pi j}{N}}\right\}\\
&=(-1)^{k}\sum_{j=-(N-1)}^{(N-1)}{\vphantom{\sum}}''e^{\frac{i\pi j (k-1)}{N}}\mathfrak{F}_{\frac{N+k-1}{N},\frac{1}{N}}\left(\frac{e^{-\frac{i\pi j}{N}}}{x^{1/N}}\right),
\end{aligned}
where in the last step we employed the definition of \mathfrak{F}_{k,N}(x) from (?).
We next calculate the residues. We break this calculation into different cases depending on whether N divides k and k-1 or not. It boils down to only three cases: N\nmid k and N\nmid(k-1), N|k and N|(k-1) as if N divides k then it cannot divide k-1 and vice-versa.
Case I: Let N\nmid k and N\nmid (k-1). Observe that the integrand has simple poles at s=0 due to \zeta(1-s), and at s=1-k-N, 1-k+Nj, where 1\leq j\leq \lfloor\frac{k-1}{N}\rfloor, due to \sin\left(\frac{\pi}{N}(1-s-k)\right). It also has double pole at s=1-k due to \sin\left(\frac{\pi}{N}(1-s-k)\right) and \zeta\left(1+\frac{s+k-1}{N}\right). These can be evaluated to as:
\begin{aligned}
R_{0}&=-\frac{\pi\zeta\left(\frac{N+k-1}{N}\right)}{\sin\left(\frac{\pi}{N}(k-1)\right)}\\
R_{1-k-N}&=\frac{N}{2}\zeta(k+N)x^{\frac{1-k-N}{N}}\\
R_{1-k}&=N\left\{N\zeta'(k)-(\gamma+\log(x))\zeta(k)\right\}x^{\frac{1-k}{N}}\\
R_{1-k+Nj}&=N\sum_{j=1}^{\lfloor\frac{k-1}{N}\rfloor}(-1)^j\zeta(1+j)\zeta(k-Nj)x^{\frac{k-1}{N}+j}.
\end{aligned}
Case II: Let N|k. Therefore, k=mN for some m\in\mathbb{N}. This implies \sin\left(\frac{\pi}{N}(1-s-k)\right)=(-1)^{m+1}\sin\left(\frac{\pi}{N}(1-s)\right). Hence, the integrand has an extra simple pole at s=1 besides all other poles in the previous case. The residue at the pole s=1 is:
\begin{aligned}
R_1=-\frac{N}{2}(-1)^{k/N}x^{1/N}\zeta\left(\frac{k+N}{N}\right).
\end{aligned}
Case III: Let N|(k-1). In this case, \sin\left(\frac{\pi}{N}(1-s-k)\right) also has pole at s=0 which was not the case before (this was j=\lfloor\frac{k-1}{N}\rfloor case in Case I). This implies that the integrand has now double pole at s=0 along with other poles in the Case I, but now j runs between 1\leq j\leq \lfloor\frac{k-1}{N}\rfloor-1. Therefore, we only need to calculate the residue at s=0, that is:
\begin{aligned}
R_0=(-1)^{\frac{k-1}{N}}\left\{\big(N\gamma-\log(x)\big)\zeta\left(\frac{N+k-1}{N}\right)-\zeta'\left(\frac{N+k-1}{N}\right)\right\}.
\end{aligned}
We now combine all of the residues from (?), (?), and (?) together, then it is nothing but the term \mathscr{R}_{k,N}(x) defined in the statement of the theorem according to the different cases.
Theorem now follows upon using the above facts and (Proof) in (Proof).