Let $A = \{1,2,\cdots, m+n\}$, where m and n are positive integers and let the function $f:A \to A$ be defined by $f(i)=i+1$ for $i \in A\backslash \{m,m+n\}, f(m)=1, f(m+n)=m+1$. Prove that if m is even, $m=n$ if and only if there exists a function $g:A \to A$ so that $g(g(a))=f(a)\,\forall a\in A.$
For the only if direction, note that the function $g(i) = m+i$ for $1\leq i\leq m, g(m+i)=i+1$ for $1\leq i\leq m-1, g(2m)=1$ works. For the converse, let $M=\{1,2,\cdots, m\}$ and observe that $f$ acts the same way on M as the cycle $(1\,2\,\cdots\,m).$ Also, note that for any $i\in M,$ there exists a smallest $j\ge 1$ so that $f^j(i)=i$, where $f^j$ denotes the j fold composition of f with itself. Indeed, in the sequence $i,f(i),f^2(i),\cdots $ there is a repeated element. Since the sequence lies in M, we can find indices $j < k$ so that $f^j(i) = f^k(i)\Rightarrow f^{k-j}(i) = i$ since f is injective (we only need the fact that f is injective on M since f maps M to M). Also, it seems that $g(M)\cap M = g(A\backslash M)\cap (A\backslash M)=\emptyset$ but I'm not sure how to prove this. If I can show that $A\backslash M $ has the same cardinality as M, I'm done. For instance, from the injectivity of g and the above claims, since $g$ maps $M$ to $A\backslash M, |M|\leq |A\backslash M|$ and similarly $|A\backslash M|\leq |M|$.
The "only if" direction has been shown in the question. This answer shows the "if" direction.
Assume $m$ is even and there exists a function $g:A \to A$ so that $g(g(a))=f(a)\,\forall a\in A.$ We will show $m=n$.
Claim: $f^i(1)=r_m(1+i)$, where $i\ge0$ and $r_m(x)$ is the least positive integer that is congruent to $x$ modulo $m$. For examples, $r_2(1)=1$, $r_2(2)=2$, $r_2(3)=1$, and $r_m(m+1)=1$.
Proof: Straightforward induction. $\quad\checkmark$
Claim: We can switch the order of $f$'s and $g$'s arbitrarily when applying them successively.
Proof: $f\circ g = g\circ f$ since $f(g(a)) = g(g(g(a)))= g(f(a))$ for all $a$. $\quad\checkmark$
Let $M=\{1,2,\cdots, m\}$ and $N=\{m+1, m+2, \cdots, m+n\}$.
Claim: $g(1)\in N$.
Proof: Towards a contradiction, assume $g(1)\in M$. So $g(1)=1+\delta=f^\delta(1)$ for $0\le\delta<m$. Since $f$ and $g$ commutate, $$g^m(1)=(f^\delta)^m(1).$$ However, $\text{LHS}=f^{m/2}(1)=1+m/2$ while $\ \text{RHS}=f^{\delta m}(1) =r_m(1+\delta m)=1$. This contradiction implies $g(1)\not\in M$. Since $g(1)\in A=M\cup N$, we have $g(1)\in N$. $\quad\checkmark$
Claim: $m=n$.
Proof. It is enough to show the map $a\mapsto g(a)$ is a bijection from $M$ to $N$.
If $a\in M$, $a=f^i(1)$ for some $i\ge0$. $\ g(a)=g(f^i(1))=f^i(g(1))\in N$.
Since $f$ is injective and $g(g(a))=f(a)$, that map is injective.
If $b\in N$, then $b=f^j(g(1))$ for some $j\ge0$. Since $b=g(f^j(1))\in g(M)$, that map is surjective. $\quad\checkmark$