<s>[INST] On the lengths of the cycles of random permutations A random permutation of $n$ from $n$ is chosen. What is the mathematical expectation of the sum of squares of lengths of its cycles?
 [/INST] The exponential generating function of permutations by the sum of the squares of the lengths of its cycles is
$$ G(z, u) = 
\exp
\left(u z + \frac{1}{2} u^4 z^2 + \frac{1}{3} u^9 z^3 + \frac{1}{4} u^{16} z^4 \cdots\right)$$
which means that the probability generating function of the expectation that we are looking for is
$$ \left.\frac{\partial}{\partial u} G(z, u) \right|_{u=1} \\= 
\left.
\exp
\left(u z + \frac{1}{2} u^4 z^2 + \frac{1}{3} u^9 z^3 + \frac{1}{4} u^{16} z^4 \cdots\right)
\left(z + 2 u^3 z^2 + 3 u^8 z^3 + 4 u^{15} z^4 \cdots\right)
\right|_{u=1} \\=
\exp\log\frac{1}{1-z}\times \frac{z}{(1-z)^2} = 
\frac{1}{1-z}\times \frac{z}{(1-z)^2} =
\frac{z}{(1-z)^3}.$$
The conclusion is that the expectation we are trying to compute is given by
$$[z^n]  \left.\frac{\partial}{\partial u} G(z, u) \right|_{u=1} =
[z^n] \frac{z}{(1-z)^3} = \frac{1}{2} n (n+1).$$
</s>