Example 5 For an integer $n(n \geqslant 4)$, find the smallest integer $f(n)$ such that for any positive integer $m$, in any $f(n)$-element subset of the set $\{m$, $m+1, \cdots, m+n-1\}$, there are at least three pairwise coprime elements.
$(2004$, National High School Mathematics Competition)
Let $m=2$.
By the principle of inclusion-exclusion, the number of elements in the set $\{2,3, \cdots, n+1\}$ that are divisible by 2 or 3 is
$$
\left[\frac{n+1}{2}\right]+\left[\frac{n+1}{3}\right]-\left[\frac{n+1}{6}\right] \text {. }
$$

Any three of these numbers will either have two that are both divisible by 2, or two that are both divisible by 3, but they will not be pairwise coprime. Therefore,
$$
\begin{array}{l}
f(n) \geqslant\left[\frac{n+1}{2}\right]+\left[\frac{n+1}{3}\right]-\left[\frac{n+1}{6}\right]+1 . \\
\text { Let }\left[\frac{n+1}{2}\right]+\left[\frac{n+1}{3}\right]-\left[\frac{n+1}{6}\right]+1=k_{n} .
\end{array}
$$

Next, we prove that for any positive integer $m$, in any $k_{n}$-element subset of the set $\{m, m+1, \cdots, m+n-1\}$, there are at least three elements that are pairwise coprime. Thus, we have
$$
f(n)=\left[\frac{n+1}{2}\right]+\left[\frac{n+1}{3}\right]-\left[\frac{n+1}{6}\right]+1 \text {. }
$$
(1) Three consecutive integers $2 u+1$, $2 u+2, 2 u+3$ with the first and last being odd are pairwise coprime. Therefore, in any four consecutive integers, there are three that are pairwise coprime.
(2) In any five-element subset $A$ of $\{a, a+1, \cdots, a+5\}$, there are at least three elements that are pairwise coprime.

In fact, if the number $b$ not in the set $A$ is one of $a$, $a+1$, $a+4$, or $a+5$, then the set $A$ contains four consecutive integers;

If $b$ is an even number among $a+2$ and $a+3$, then the set $A$ contains three consecutive integers with the first and last being odd;
If $b=a+2$ is odd, then $a$ is odd,
$$
(a, a+4)=(a, a+1)=(a+3, a+4)=1 \text {, }
$$
and $(a, a+3)=(a, 3)$ and $(a+1, a+4)=(a+1,3)$ are either 1 or 3, and they cannot both be 3 at the same time. Therefore, at least one of $(a, a+1, a+4)$ and $(a, a+3, a+4)$ is pairwise coprime;

When $b=a+3$ is odd, similarly, at least one of $(a+1, a+2, a+5)$ and $(a+1, a+4, a+5)$ is pairwise coprime.
(3) Let $n=6 q+r$. Any $n$ consecutive integers can be divided into $q$ consecutive 6-number segments $I_{i}$ and one consecutive $r$-number segment $R$ (when $r=0$, this segment is empty). List the corresponding $k_{n}$ values for $r=0,1, \cdots, 5$ as shown in Table 1.
Table 1
\begin{tabular}{|c|c|c|c|c|c|c|}
\hline$r$ & 0 & 1 & 2 & 3 & 4 & 5 \\
\hline$k_{n}$ & $4 q+1$ & $4 q+2$ & $4 q+3$ & $4 q+4$ & $4 q+4$ & $4 q+5$ \\
\hline
\end{tabular}

From this, we know that any $k_{n}$-element subset either contains five numbers from some segment $I_{i}$, or contains four consecutive numbers from segment $R$. By (2), there must be three elements that are pairwise coprime.