TITLE: Determine the number of elements $f$ of $S_n$ for which $f(1) \ne 1$ and $f(2) \ne 2$.
QUESTION [5 upvotes]: $S_n$ is the group consisting of the set of all bijections from $\{1,2,...,n\}$ to $\{1,2,...,n\}$.
For $n\geq 2$, determine the number of elements $f$ of $S_n$ for which $f(1) \ne 1$ and $f(2) \ne 2$.
The way I tried to solve it is by using the fact that $$|A \cup B|=|A|+|B|-|A\cap B|$$ Where $|A|$ is the amount of possible functions such that $f(1)\ne 1$ and $|B|$ is the amount of possible functions such that $f(2)\ne 2$. With this in mind, I let $|A| = n^n-n$ and $|B|=n^n-n$ but now I am stuck. Please help!

REPLY [3 votes]: Normally $S_n$ denotes the set of permutations of $\{1,2,\ldots,n\}$,
that is the bijections from the set to itself. I'll assume you mean
$S_n$ in the remainder of your question. If you really mean $F_n$
you will have to amend the argument appropriately.
Better to let $A$ and $B$ denote the sets of elements of $S_n$
with $f(1)=1$ and $f(2)=2$ respectively. The number of elements
of $S_n$ with both $f(1)\ne1$ and $f(2)\ne2$ is then
$$|S_n|-|A\cup B|=|S_n|-|A|-|B|+|A\cap B|.$$
As we are dealing with permutations, $|S_n|=n!$. Now $A$
is basically the set of permutations of $\{2,3,\ldots,n\}$
so $|A|=(n-1)!$. Similarly $|B|=(n-1)!$. Then $A\cap B$
is formed of the permutations with $f(1)=1$ and $f(2)=2$.
These permute $\{3,4,\ldots,n\}$ freely, so there are $(n-2)!$
of them, etc.