2. Let the set $S_{n}=\{1,2, \cdots, n\}$. Find all positive integers $n$, such that there exist $f: S_{n} \rightarrow S_{n}, g: S_{n} \rightarrow S_{n}$ satisfying for any $x$, exactly one of $f(g(x))=x, g(f(x))=x$ holds.
2. First, prove: when $n=2 m\left(m \in \mathbf{Z}_{+}\right)$, there exist functions that satisfy the conditions.
Definition: $f(x)=\left\{\begin{array}{ll}x, & 1 \leqslant x \leqslant m ; \\ x-m, & m+1 \leqslant x \leqslant 2 m,\end{array}\right.$
$$
g(x)=\left\{\begin{array}{ll}
x+m, & 1 \leqslant x \leqslant m ; \\
x, & m+1 \leqslant x \leqslant 2 m .
\end{array}\right.
$$

Notice that, the ranges of all functions $f(x)$ and $g(x)$ are contained in $S_{n}$.
Thus, there indeed exist functions $S_{n} \rightarrow S_{n}$.
Since the range of $f$ is $\{1,2, \cdots, m\}$ and the range of $g$ is $\{m+1, m+2, \cdots, 2 m\}$, we have:
When $x \geqslant m+1$, $f(g(x)) \neq x$;
When $x \leqslant m$, $g(f(x)) \neq x$.
Moreover, for $x \in S_{n}$, exactly one of the following holds:
$$
f(g(x))=x, g(f(x))=x
$$

Assume $n$ is odd, let $n=2 m+1(m \in \mathbf{N})$, and the functions $f \cap g$ satisfy the conditions. Without loss of generality, assume that there are at least $m+1$ elements $x_{1}, x_{2}, \cdots, x_{m+1}$ in $S_{n}$ such that
$$
f(g(x))=x .
$$

Assume for $i 、 j(i \leqslant j \leqslant m+1)$, we have
$$
g\left(x_{i}\right)=x_{j} .
$$

Then $f\left(x_{j}\right)=f\left(g\left(x_{i}\right)\right)=x_{i}$,
$$
g\left(f\left(x_{j}\right)\right)=g\left(x_{i}\right)=x_{j} \text {. }
$$

But for $x=x_{j}$, $f(g(x))=x$ and $g(f(x))=x$, which is a contradiction.
Thus, for all $i(1 \leqslant i \leqslant m+1)$,
$$
g\left(x_{i}\right) \neq x_{j}(1 \leqslant j \leqslant m+1) \text {. }
$$

Since $S_{n}$ has $m$ elements that are not equal to $x_{j}(1 \leqslant$ $j \leqslant m+1)$, and for $i(1 \leqslant i \leqslant m+1)$, there are $m+1$ values, by the pigeonhole principle, we have
$$
g\left(x_{k}\right)=g\left(x_{l}\right)(1 \leqslant k<l \leqslant m+1) .
$$

But $x_{k}=f\left(g\left(x_{k}\right)\right)=f\left(g\left(x_{l}\right)\right)=x_{l}$, which is a contradiction.
Therefore, when $n$ is odd, there do not exist functions $f$ and $g$ that satisfy the conditions.

Thus, there exist functions $f$ and $g$ that satisfy the conditions if and only if $n$ is even.