21. Answer: 81.
Suppose $f(f(f(n)))=n$ for all $n$. For some $k \in\{0,1,2\}$, there exist distinct $a_{i}, b_{i}, c_{i}, i \leq k$, such that $f\left(a_{i}\right)=b_{i}, f\left(b_{i}\right)=c_{i}$ and $f\left(c_{i}\right)=a_{i}$ and $f(n)=n$ if $n \neq a_{i}, b_{i}, c_{i}$. So the total number of required functions is
$$
\binom{6}{6}+\binom{6}{3} \times 2+\frac{1}{2} \times\binom{ 6}{3}\binom{3}{3} \times 2^{2}=81 .
$$
21. Let $A=\{1,2,3,4,5,6\}$. Find the number of distinct functions $f: A \rightarrow A$ such that $f(f(f(n)))=n$ for all $n \in A$.