Problem

Source: Baltic Way 2024, Problem 9

Tags: function, combinatorics, combinatorics proposed



Let $S$ be a finite set. For a positive integer $n$, we say that a function $f\colon S\to S$ is an $n$-th power if there exists some function $g\colon S\to S$ such that \[ f(x) = \underbrace{g(g(\ldots g(x)\ldots))}_{\mbox{\scriptsize $g$ applied $n$ times}} \]for each $x\in S$. Suppose that a function $f\colon S\to S$ is an $n$-th power for each positive integer $n$. Is it necessarily true that $f(f(x)) = f(x)$ for each $x\in S$?