9. Given a positive integer $n \geqslant 3$, the function $f:\{1,2, \cdots, n\} \rightarrow\{1,2, \cdots, n\}$ satisfies $f(f(k))=(f(k))^{3}-$ $6(f(k))^{2}+12 f(k)-6, \forall k \in\{1,2, \cdots, n\}$, find the number of all such functions.
9. Solution: Let $M=\max _{1 \leq k<n} f(k)$, then $M \in\{1,2, \cdots, n\}$, and there exists $k_{0} \in\{1,2, \cdots, n\}$, such that $f\left(k_{0}\right)=M$; taking $k=k_{0}$ in the given equation, we get $f(M)=M^{3}-6 M^{2}+12 M-6 . \because \quad f(M) \leqslant M, \therefore M \geqslant M^{\beta}-6 M^{2}+12 M-6$, i.e., $M^{\beta}-$ $6 M^{2}+11 M-6 \leqslant 0$, or $(M-1)(M-2)(M-3) \leqslant 0, \therefore M \in\{1,2,3\}$, the range of the function $C=\{f(k) \mid 1 \leqslant k \leqslant$ $n\} \subset\{1,2,3\}, 1 \leqslant \operatorname{card}(C) \leqslant 3$. Furthermore, for any $k \in\{1,2, \cdots, n\}$, we always have $\quad f(f(k))=(f(k)-1)(f(k)-2)$ $(f(k)-3)+f(k)=f(k), \therefore f(k)=\left\{\begin{array}{l}k, k \in \mathbf{C} \\ \in \mathbf{C}, k \notin \mathbf{C}\end{array}\right.$, thus we count the functions as follows. When $\operatorname{card}(C)=1$, the number of functions is $C_{3}^{1}=3$; when $\operatorname{card}(C)=2$, the number of functions is $C_{3}^{2} 2^{n-2}=3 \cdot 2^{n-2}$; when $\operatorname{card}(C)=3$, the number of functions is $C_{3}^{3} 3^{n-3}=3^{n-3}$. Therefore, the total number of functions is $3^{n-3}+3 \cdot 2^{n-2}+3$.