Example 5 Calculate the number of composite and prime numbers not exceeding 120.
$$
\begin{array}{l}
\text { Solution: Let } S_{1}=\{a|1 \leqslant a \leqslant 120,2| a\}, S_{2}=\{b|1 \leqslant b \leqslant 120,3| b\}, S_{3} \\
=\{c|1 \leqslant c \leqslant 120,5| c\}, S_{4}=\{d|1 \leqslant d \leqslant 120,7| d\}, \text { then } \\
\quad\left|S_{1}\right|=\left[\frac{120}{2}\right]=60,\left|S_{2}\right|=\left[\frac{120}{3}\right]=40,\left|S_{3}\right|=\left[\frac{120}{5}\right]=24,\left|S_{4}\right| \\
=\left[\frac{120}{7}\right]=17, \text { and we have }\left|S_{1} \cap S_{2}\right|=\left[\frac{120}{2 \times 3}\right]=20,\left|S_{2} \cap S_{3}\right|=\left[\frac{120}{2 \times 5}\right]= \\
12,\left|S_{1} \cap S_{4}\right|=\left[\frac{120}{2 \times 7}\right]=8,\left|S_{2} \cap S_{3}\right|=\left[\frac{120}{3 \times 5}\right]=8,\left|S_{2} \cap S_{4}\right|= \\
{\left[\frac{120}{3 \times 7}\right]=5,\left|S_{3} \cap S_{4}\right|=\left[\frac{120}{5 \times 7}\right]=3,\left|S_{1} \cap S_{2} \cap S_{3}\right|=\left[\frac{120}{2 \times 3 \times 5}\right]=} \\
4,\left|S_{1} \cap S_{2} \cap S_{4}\right|=\left[\frac{120}{2 \times 3 \times 7}\right]=2,\left|S_{2} \cap S_{3} \cap S_{4}\right|=\left[\frac{120}{2 \times 5 \times 7}\right]=1, \\
\left|S_{1} \cap S_{2} \cap S_{3} \cap S_{4}\right|=\left[\frac{120}{2 \times 3 \times 5 \times 7}\right]=0 .
\end{array}
$$

By the principle of inclusion-exclusion, we have $\left|S_{1} \cup S_{2} \cup S_{3} \cup S_{4}\right|=92$. Since $2,3,5,7$ are among these 92 numbers and they are not composite numbers, the number of composite numbers is $92-4=88$ (numbers). Since 1 is not a prime number, the number of prime numbers is $120-88-1=29$ (numbers).
$$