Solution (source code)

= Solution

The given logarithmic moment is
$$
\ell=\frac2{n(n+1)}\sum_{r=1}^nr\log_2r,
$$
where the $r=1$ term is zero. It is attained by the positive distribution
$$
q_r=\frac{2r}{n(n+1)},
$$
whose <probabilities> <sum> to one. Write $A=2/[n(n+1)]$, so $\log_2q_r=\log_2A+\log_2r$. For any distribution $p$ with the required logarithmic moment,
$$
d(p,q)=-H(p)-\log_2A-\ell=H(q)-H(p).
$$
Consequently the unique maximizer and its <Shannon entropy>[entropy] are
$$
\boxed{p_Z(r)=\frac{2r}{n(n+1)},\qquad H(Z)_{\max}=\log_2\frac{n(n+1)}2-\ell.}
$$
The increasing weights are consistent with the prescribed moment; they need not be a decreasing <power law>.