Solution (source code)

= Solution
{c}

The <function> $x\sin(px)$ is an <even function>, so every <Fourier sine coefficient> is zero. Introduce the auxiliary <integral>
$$
I_k=\int_0^\pi x\sin(kx)\,dx.
$$
For a nonzero integer $k$, <integration by parts> gives
$$
I_k=\left[-\frac{x\cos(kx)}k+\frac{\sin(kx)}{k^2}\right]_0^\pi
=-\frac{\pi(-1)^k}{k},\qquad I_0=0.
$$
Consequently
$$
a_0=\frac2\pi I_p=\frac{2(-1)^{p+1}}p.
$$
For $n\geq1$, a <product-to-sum formula> yields
$$
a_n=\frac1\pi(I_{p+n}+I_{p-n}).
$$
If $n\ne p$, this becomes
$$
a_n=-(-1)^{p+n}\left(\frac1{p+n}+\frac1{p-n}\right)
=\frac{2p(-1)^{p+n}}{n^2-p^2}.
$$
The exceptional <Fourier coefficient> at $n=p$ must be evaluated before dividing by $p-n$:
$$
a_p=\frac1\pi(I_{2p}+I_0)=-\frac1{2p}.
$$
Thus the full <Fourier series> is
$$
\boxed{x\sin(px)=\frac{(-1)^{p+1}}p-\frac{\cos(px)}{2p}
+2p\!\sum_{\substack{n\geq1\\n\ne p}}
\frac{(-1)^{p+n}\cos(nx)}{n^2-p^2}}.
$$
This equality holds on $[-\pi,\pi]$ and by <periodicity> everywhere. Indeed the <periodic extension> is continuous at the joined endpoints, since both endpoint values are zero, and is piecewise smooth. The theorem on <pointwise convergence of a piecewise smooth Fourier series> therefore applies, including at the endpoints. The <Fourier coefficients> also decay as $n^{-2}$, making the resulting <series> absolutely and uniformly convergent.