Let $$f_n = |\{\pi \in S_n \space | \space \forall 1 \leq i \leq n : \pi(i) \neq i \}|$$
Prove that $f_1 = 0, f_2 = 1$, and $f_n = (n-1)(f_{n-1} + f_{n-2})$. Furthermore, prove that this recurrence relation implies $$f_n = n!\sum_{k=0}^{n}\frac{(-1)^k}{k!}$$
As long as I understood, it says that we are interested about permutations of $n$ numbers, such that none of the numbers are in their original position. I tested it for first non-trivial and hand-testable value of $n$ which is $n=3$. I have two permutation that satisfy the condition, and they are $(312)$ and $(231)$. Plugging the numbers into $f_n$ yields $f_3 = 2\cdot(f_2 + f_1) = 2 \cdot (1 + 0) = 2$, so clearly the identity holds. But how can I prove it for arbitrary n? I tried to do something like induction, but I got stuck. And how can I prove the recurrence relation?
A permutation having the property you describe is named a derangement.
First, let's prove that for all $n \ge 0$, $$f_{n+2}=(n+1)(f_{n+1}+f_n).$$ We denote $$\begin{cases} E_{n+1} &= \{1 & 2 \ \dots \ k-1 \ & k & k+1 \ \dots \ n+1\}\\ G_{n+1} &= \{1 & 2 \ \dots \ k-1 \ & n+2 & k+1 \ \dots \ n+1\} \end{cases}$$ and $$R_n=\{\pi \in S_n \space | \space \forall 1 \leq i \leq n : \pi(i) \neq i \}.$$
Consider the elements $\sigma \in R_{n+2}$ such that $\sigma(n+2)=k <n+2$.
We have two cases.
As both both cases are mutually exclusive and the only possible, we get the expected relation $$f_{n+2}=(n+1)(f_{n+1}+f_n)$$
$f_n = n!\sum_{k=0}^{n}\frac{(-1)^k}{k!}$ can then be proved by induction.