If $A=\left\{1,2,3,4,5\right\}$, then find the number of functions satisfying $$f(f(f(x)))=f(f(x)), \forall x \in A \to (1)$$ Related: Number of functions satisfying $f(f(x))=f(x)$.
I actually took the help from the thread above and tried as follows: From $1$ we see that if $y \in \operatorname{im}(f)$, then $$f(f(y))=f(y) \to (2).$$ Now consider the following cases:
Case $1.$ If $\operatorname{im}(f)$ contains only one element, then trivially its a constant function and satisfies $(1)$. Number of such functions is $\binom{5}{1}=5$.
Case $2.$ Let $\operatorname{im}(f)$ contains only two elements. WLOG let us assume $\operatorname{im}(f)=\left\{1,2\right\}$
From $(2)$ we have $$f(f(1))=f(1), f(f(2))=f(2)$$ $\implies$ $$f(f(f(1)))=f(f(1)), \:f(f(f(2)))=f(f(2))$$
Now if $f(1)=2$ then it implies $f(2)=2$ and let $f(3)=1, f(4)=2,f(5)=2$, then we have $$f(f(f(3)))=2=f(f(3))$$ $$f(f(f(4)))=2=f(f(4))$$ $$f(f(f(5)))=2=f(f(5))$$ So definitely this is one of the function which satisfies the hypothesis. But how to count number of such functions? What about the upcoming cases?

Assume the set is $\{1,\dots,n\}$. Define the resistance of an element as the lowest $k$ such that $f^k(x) = f^{k+1}(x)$, We require that each element has resistance $0,1$ or $2$.
How many such functions exist with $a$ elements of resistance $0$ and $b$ elements of resistance $1$?
There are $\binom{n}{a,b,n-a-b}$ ways to select the elements of resistance $0,1$ and $2$.
Then there are $a^b$ ways to assign $f(x)$ for every element of resistance $1$, and there are $b^{n-a-b}$ ways to assign $f(x)$ for every element of resistance $2$.
Therefore we have that the number of functions is equal to $$\sum\limits_{i=1}^n\sum\limits_{j=0}^{n-i}\binom{n}{a,b,n-a-b} a^b b^{n-a-b}$$
Looking at OEIS we get https://oeis.org/A000949 where the same formula is provided.
The following C++ code evaluates this for $n=5$ and give 756.
Brute force checker: