Example 7 Let $n(n \geqslant 2)$ be an integer. $S$ is a subset of the set $\{1,2, \cdots, n\}$, where no number in $S$ divides another, and no two numbers are coprime. Find the maximum number of elements in $S$.
(2005 Balkan Regional Olympiad)
Define the mapping $f$:
$$
S \rightarrow\left\{\left[\frac{n}{2}\right]+1,\left[\frac{n}{2}\right]+2, \cdots, n\right\},
$$
$f$ transforms $x \in S$ into $2^{k} x \in\left(\frac{n}{2}, n\right]$ (where $k$ is a non-negative integer), and the elements in the set $\left\{\left[\frac{n}{2}\right]+1,\left[\frac{n}{2}\right]+2, \cdots, n\right\}$ satisfy the condition that "no number divides another number."

It is easy to see that this is an injection, because if there exist non-negative integers $k_{1} 、 k_{2}$, such that $2^{k_{1}} x=2^{k_{2}} y$, without loss of generality, assume $k_{1}1$.
And $(x, y) \mid(f(x), f(y))$, then $(f(x), f(y))>1$.
Thus, $f(S)$ does not contain two consecutive integers.
Therefore, $|S| \leqslant\left[\frac{\frac{n}{2}+1}{2}\right]=\left[\frac{n+2}{4}\right]$.
Furthermore, when $S=\left\{k \mid k\right.$ is even, $\left.k>\frac{n}{2}\right\}$, $S$ meets the requirements of the problem.
Hence, the maximum value of $\mid S$ | is $\left[\frac{n+2}{4}\right]$.