Question 25 Let $a, b \in \mathbf{N}, 1 \leqslant a \leqslant b, M=\left[\frac{a+b}{2}\right]$, define the function $f: \mathbf{Z} \rightarrow$ $\mathbf{Z}$ as
$$
f(n)=\left\{\begin{array}{ll}
n+a & n<M ; \\
n-b & n \geqslant M .
\end{array}\right.
$$

Let $f^{[1]}(n)=f(n), f^{[i+1]}=f\left(f^{[i]}(n)\right), i=1,2, \cdots$, find the smallest positive integer $k$, such that $f^{[k]}(0)=0$.
(1990 31st IMO Preliminary Question, provided by Norway)
First, consider the case where $(a, b)=1$.
Let the set $S=\{n \mid M-b \leqslant n \leqslant M+a-1, n \in \mathbf{Z}\}$, then $f(S) \subseteq S$, and $0 \in S$. Let $k \geqslant 1$, and $f^{[k]}(0)=0$. Since $f(m)=m+a$ or $m-b$, $k$ can be written as $k=r+s$ and $r a-s b=0$. By $(a, b)=1$, we get $r \geqslant b, s \geqslant a, k \geqslant a+b$.
On the other hand, $f^{[a+b]}(0)=r a-s b$, where $r+s=a+b$, so $f^{[a+b]}(0)=r a-s b=(a+b)(a-s)$.

Since $f^{[a+b]}(0) \in S$, and the only multiple of $(a+b)$ in $S$ is 0, it follows that $f^{[a+b]}(0)=0$.
In summary, the smallest natural number $k$ such that $f^{[k]}(0)=0$ is $k=a+b$.
(For the general case, let $a=a_{1}(a, b), b=b_{1}(a, b), S_{1}=\left\{n \mid M-b_{1} \leqslant n \leqslant M+a_{1}-1, n \in \mathbf{Z}\right\}$, and similarly we can obtain the result.)