Solution (source code)

= Solution

Writing $p_n=\mathbb P(X=n)$, the ordinary <probability generating function> is
$$
P_X(s)=\mathbb E[s^X]=\sum_{n=1}^Kp_ns^n.
$$
Its finite sum can be differentiated termwise, giving
$$
\boxed{\mathbb EX=P_X'(1).}
$$
The <Dirichlet probability generating function> is the different transform $q(z)=\mathbb E[X^{-z}]$. Evaluating at $z=-1$ gives the first ordinary moment, whereas differentiation gives $q'(z)=-\sum_np_n(\log n)n^{-z}$. Therefore
$$
\boxed{\mathbb EX=q(-1),\qquad\mathbb E[\log X]=-q'(0).}
$$
There is no convergence issue because the support is finite and all its values are positive.