Finding the functions verifying that for all $x$, we get $g \circ \dots \circ g(x)=x$ where the number of composition depends on $x$. Let $g:[0,1]\to[0,1]$ a continuous function verifying $g(0)=0$ and for every $x$ in $[0,1]$, there exists a non zero positive integer $n=n(x)$ such that $g^n(x)=x$ where $g^n$ is $g \circ \dots \circ g$ ($g$ appears $n$ times, $g^0=Id$).
I'm asked to show that $g$ in injective and surjective, then deduce that $g$ is the identity.
For the surjection, I think it's easy for all $y$ in $[0,1]$, there exists $n$ such that $g^n(y)=y$ so $g(g^{n-1}(y))=y$.
I'm having trouble showing that it's injective. If I take $x,y$ such that $g(x)=g(y)$. There will exist $n,m$ such that $g^n(x)=x$ and $g^m(y)=y$. By symmetry, we can suppose $n>m$ (if $n=m$, we get directly $x=y$), and by Euclidian division, we have $(q,r)$ such that $n=mq+r$ where $0\leq r<m$, and so :  $g^r(y)=x$. This is what I've thought of so far, to finish the proof, I'll have to show that $r=0$, or that $n$ divides $m$. (Maybe I need to use the continuity and that $g(0)=0$ since I haven't used them thus far).
Any help/hints for the injection part or deduction part will be appreciated.
 A: Note that if $g^n(x)=x$ for some positive integer $n$, then $g^{nk}(x)=x$ for all positive integers $k$. Indeed, it is clear for $k=1$, and if $k^{nk}(x)=x$, we have that
$$
g^{n(k+1)}(x)=g^{n}(g^{nk}(x)) = g^n(x) = x.
$$
Now, given that $g^n(x)=x$, $g^{m}(y)=y$ and that $g(x)=g(y)$, then we have that $g^k(x)=g^k(y)$ for every positive integer $k$, in particular, taking $k=nm$, we have by the previous part that $g^{nm}(x)=x$ and $g^{nm}(y)=y$, and
$$
x = g^{nm}(x) = g^{nm}(y) = y,
$$
which proves the injectivity of $g$.
Now, note that $g(1)=1$ because if $g(a)=1$, for some $0<a<1$ then $g(1)<1$ as $g$ is bijective and as $g$ is continuous and $g(0)=0$, there exists $c\in (0,a)$ and $d\in (a,1)$ such that
$$
g(c) = \frac{g(1)+1}{2} \quad \text{and} \quad g(d) = \frac{g(1)+1}{2}
$$
(just apply the intermediate value theorem). This contradicts the injectivity of $g$. Thus $g(1)=1$.
This shows that $g$ must be strictly increasing (Exercise! You will need again the continuity of $g$). Thus, if $g(x)\neq x$ for some $x$, assume, for example, that $g(x)>x$ (the case $g(x)<x$ is analogous), and let $n$ be such that $g^n(x)=x$. Then $g^2(x)=g(g(x))>g(x)>x$, and inductively we see that
$$
g^n(x) > g^{n-1}(x) > \cdots > g(x)>x,
$$
which is absurd as $g^n(x)=x$.
Thus $g(x)=x$ for all $x$, that is, $g$ is the identity map.
