TITLE: Counting the sum of cycles of the elements in $S_n$.
QUESTION [6 upvotes]: Let $\sigma\in S_n$ be given. Let us write $\sigma$ in its disjoint cycle decomposition. Define by $w(\sigma)$ the number of cycles (for instance if we have the permutation $1\mapsto 2, 2\mapsto 4, 3\mapsto 3, 4\mapsto 1, 5\mapsto 5$ we write it as $(124)(3)(5)$ so $w(\sigma)=3$).
I was asked to find $$A_n=\sum_{\sigma\in S_n}w(\sigma)$$I found the recursive formula $$A_n=n!+(n-1)!\left[\frac{A_{n-1}}{(n-1)!}+\frac{A_{n-2}}{(n-2)!}+\ldots+\frac{A_{1}}{1!}\right]$$
I was trying to tinker around with it to see if I could get a formula that does not rely on recursion, but failed at it. Any help or hint that would lead me towards making my solution for $A_n$ "better".

REPLY [4 votes]: This question is best addressed using the symbolic method.
Permutations are sets of cycles, having combinatorial class specification
$\mathfrak P(\mathfrak C(\mathfrak Z))$. Hence the corresponding exponential generating function (EGF) is $$ \exp \log \frac{1}{1-z} = \frac{1}{1-z},$$ where $$ \log \frac{1}{1-z} $$ is the EGF of labelled cycles. (These two are easily verified as there are $n!$ permutations and $n!/n$ cycles.)
If we want to count the number of cycles we need to mark each cycle with a new variable, $u$, which gives the mixed generating function
$$G(z, u) = \exp \left( u \log \frac{1}{1-z} \right).$$
Now a term $u^k z^n / n!$ in $G(z, u)$ represents a permutation of $n$ elements having $k$ cycles. To count these, we need to differentiate with respect to $u$ and set $u=1$, obtaining
$$ \left. \frac{d}{du} G(z, u) \right|_{u=1} =
\left. \exp \left( u \log \frac{1}{1-z} \right) \log \frac{1}{1-z} \right|_{u=1} =
\frac{1}{1-z} \log \frac{1}{1-z} .$$
But $$ [z^n] \frac{1}{1-z} \log \frac{1}{1-z} = H_n $$ by a trivial calculation and we are done.
There is much more on this method at Wikipedia.