20. Let $\mathrm{A}$ be an $n(n \geqslant 3)$ element set. When $f(x)$ is a mapping from $A$ to $A$, define: $f^{2}(x)=f(f(x))$, $f^{i+1}(x)=f\left(f^{i}(x)\right), i=2,3, \cdots$. Find the number of mappings $f$ from $A$ to $A$ that satisfy the condition that $f^{n-2}(x)$ is a constant while $f^{n-3}(x)$ is not a constant.
20. Let $A=\left\{a_{1}, a_{2}, \cdots, a_{n}\right\}, f$ be a mapping that satisfies certain conditions. Then $f$ cannot map $k(k \geqslant 2)$ elements into a cycle, i.e., it is impossible to have $f\left(a_{1}\right)=a_{2}, f\left(a_{7}\right)=a_{3}, \cdots, f\left(a_{k-1}\right)=a_{k}, f\left(a_{k}\right)=a_{1}$.
In fact, if the above situation occurs, then $f\left(\left\{a_{1}, a_{2}, \cdots, a_{k}\right\}\right)=\left\{a_{1}, a_{2}, \cdots, a_{k}\right\}$, then $f^{n-2}(x)$ cannot be a constant, leading to a contradiction.
Additionally, $f(x)$ cannot have two or more fixed points. In fact, if $f\left(a_{1}\right)=a_{1}, f\left(a_{2}\right)=a_{2}$, then $f^{n-2}(x)$ cannot be a constant.
Consider the sequence
$$
a_{1}, f\left(a_{1}\right), f^{2}\left(a_{1}\right), f^{3}\left(a_{1}\right), \cdots, f^{n-1}\left(a_{1}\right)
$$

By the pigeonhole principle, there must be two elements in (1) that are the same, but since a cycle cannot appear, there must be an $i(0 \leqslant i \leqslant n-1)$, such that
$$
f^{i}\left(a_{1}\right)=f^{i+1}\left(a_{1}\right) \text { (denote } f^{i}\left(a_{1}\right)=a_{1} \text { ). }
$$

Thus, $f\left(f^{i}\left(a_{1}\right)\right)=f^{i}\left(a_{1}\right)$.
Therefore, $f(x)$ has at least one fixed point.
In summary, $f(x)$ has exactly one fixed point, i.e., there exists a unique $x_{n} \in A$ such that $f\left(x_{n}\right)=x_{n}$. Without loss of generality, assume $f\left(a_{n}\right)=a_{n}$.
Since $f^{n-3}(x)$ is not a constant, there must exist $a_{i} \in A$ such that $f^{n-3}\left(a_{i}\right) \neq a_{n}$, thus $f^{j}\left(a_{i}\right) \neq a_{n}, 1 \leqslant j \leqslant n-3$.
Also, $a_{i}, f(a_{i}), f^{2}\left(a_{i}\right), \cdots, f^{n-3}\left(a_{i}\right)$ must all be distinct (otherwise, a cycle or a new fixed point would appear, leading to a contradiction), hence
$$
a_{1}, f\left(a_{i}\right), f^{2}\left(a_{i}\right), \cdots, f^{n-3}\left(a_{i}\right), a_{n}
$$

are $n-1$ elements taken from $A$ and arranged,
$$
a_{x_{2}}, \cdots, a_{x_{n}} \text {. (There are } C_{n}^{n-1}(n-1)!\text { ways) }
$$

and it is specified that $f\left(a_{i_{2}}\right)=a_{i_{3}}, \cdots, f\left(a_{i_{n-2}}\right)=a_{i_{n-1}}, f\left(a_{i_{n-1}}\right)=a_{i_{n}}, f\left(a_{i_{n}}\right)=a_{i_{n}}$.
And $f\left(a_{1}\right) \in\left\{a_{i_{3}}, \cdots, a_{i_{n-1}}, a_{n}\right\}$ (there are $n-2$ ways).
Thus, the number of ways to complete $f$ is
$$
C_{n}^{n-1}(n-1)!(n-2)=(n-2) n!\text { ways. }
$$

However, in the above counting, for the arrangement
$$
a_{t_{2}}, a_{i_{3}}, a_{i_{1}} \cdots, a_{i_{n}} \text {, it is specified that } f\left(a_{i_{1}}\right)=a_{i_{3}} .
$$

and the arrangement
$$
a_{i_{1}}, a_{i_{3}}, a_{i_{1}}, \cdots, a_{i_{n}} \text {, it is specified that } f\left(a_{i_{2}}\right)=a_{i_{3}} \text {, }
$$

these two different ways result in the same mapping, hence this mapping is counted twice, and there are
$$
C_{n}^{2}(n-2)!=\frac{n!}{2} \text { such mappings. }
$$

Therefore, the number of mappings that satisfy the conditions is
$$
(n-2) n!-\frac{n!}{2}=\frac{2 n-5}{2} n!\text { mappings. }
$$

In the problem of counting mappings, it is important to analyze two issues: (1) whether $f(x)$ has a fixed point; (2) whether $f(x)$ can form a cycle. The sequence (1) is also a commonly used analytical tool.

When solving problems that depend on counting or estimating the number of objects, in addition to mastering necessary counting tools such as recurrence relations, the principle of inclusion-exclusion, and combinatorial identities, it is also important to master some common methods and techniques for analyzing problems.