Solution (source code)

= Solution

The trigonometric <Chebyshev alternation theorem> says that $p_n^*\in\mathcal T_n$ is best exactly when its error has at least $2n+2$ cyclically ordered extrema of equal magnitude and alternating sign. Let $5^m\leq n<5^{m+1}$ and set $x_j=j\pi/5^{m+1}$. For every $k\geq m+1$,
$$
\cos(5^kx_j)=\cos(j\pi5^{k-m-1})=(-1)^j.
$$
Thus
$$
g(x_j)-\sum_{k=0}^mc_k\cos(5^kx_j)=(-1)^j\sum_{k=m+1}^\infty c_k.
$$
There are $2\cdot5^{m+1}\geq2n+2$ such extrema, while the <triangle inequality> bounds the tail by their common magnitude. Hence
$$
\boxed{p_n^*(x)=\sum_{k=0}^mc_k\cos(5^kx)},\qquad
\boxed{E_n(g)=\sum_{k=m+1}^\infty c_k}.
$$