Solution (source code)

= Solution

Normalize the candidate distribution by setting
$$
q_r=c2^{-r},\qquad c=\frac1{1-2^{-n}}=\frac{2^n}{2^n-1}.
$$
The supplied <finite sum> gives its <mean>
$$
\sum_{r=1}^nrq_r=c\left(2-(n+2)2^{-n}\right)=\frac{2^{n+1}-(n+2)}{2^n-1}=m.
$$
Thus it meets the <constraint>. Since $\log_2q_r=\log_2c-r$, every other distribution $p$ with <mean> $m$ satisfies
$$
d(p,q)=-H(p)-\log_2c+m=H(q)-H(p).
$$
Nonnegativity and the <equality> case in part (a) prove
$$
\boxed{p_Y(r)=\frac{2^n}{2^n-1}\,2^{-r},\qquad H(Y)_{\max}=m-\log_2\frac{2^n}{2^n-1}.}
$$
The <maximum> is unique; the <Shannon entropy>[entropy] comparison uses the fixed <mean> rather than an unconstrained optimization.