Find the number of bijections $g:S\to S$ such that $g^{g(x)}(x)=x$ $\forall x\in S$ I found a question which asks

For any function $f$, define $f^1(x)=f(x)$, and for $n\geq 2$,
$f^n(x)=f(f^{n-1}(x))$. Let $S=\{1,2,3\dots ,10\}$.
Find the number of bijections $g:S\to S$ such that $g^{g(x)}(x)=x$
$\forall x\in S$.

I know how to deal with these kind of questions if we have a specific integer at the power of $g(x)$ instead of $g(x)$ itself. That is, I can find the number of bijections which satisfy $g(x)=x$ or $g^2(x)=x$ by trying to count cycles. But, I don't have any idea how to approach this one.
Any help would be appreciated.

Hint:
Figure out what cycles are possible in this permutation. Letting $C$ be a cycle, then for any $y\in C$ with $g(x)=y$, we have
$$
g^y(x)=x
$$
This implies that $y$ is a multiple of the length of the cycle $C$. Put another way, in an cycle of length $\ell$, all the elements must be multiples of $\ell$.
How many cycles of length $2$ are therefore possible? From before, this consists of a pair of numbers which are both multiples of $2$.
How many cycles of length $3$ are therefore possible? From before, this consists of a triple of numbers which are all multiples of $3$, ordered in one of $2!$ ways.
How many cycles of length $4$ are therefore possible? From before, this consists of a quadruple of numbers which are all multiples of $4$, ordered in one of $3!$ ways. And so on...
Once you have all possible cycles (there aren't too many), it becomes a matter of counting the number of ways they can be combined without overlapping.
