Example 6 In the integers from 1 to 120, how many are composite numbers and how many are prime numbers?
If $a$ is a composite number, then there must be a prime $p \leqslant \sqrt{a}$, and $\sqrt{120}<\sqrt{121}=11$, so composite numbers not exceeding 120 must be multiples of the primes $2,3,5,7$. Let
$$
\begin{array}{l}
A_{1}=\{a|1 \leqslant a \leqslant 120,2| a\}, A_{2}=\{a|1 \leqslant a \leqslant 120,3| a\} \\
A_{3}=\{a|1 \leqslant a \leqslant 120,5| a\}, A_{4}=\{a|1 \leqslant a \leqslant 120,7| a\}
\end{array}
$$

Then
$$
\begin{array}{l}
\left|A_{1}\right|=\left[\frac{120}{2}\right]=60,\left|A_{2}\right|=\left[\frac{120}{3}\right]=40,\left|A_{3}\right|=\left[\frac{120}{5}\right]=24,\left|A_{4}\right|=\left[\frac{120}{7}\right]=17 \\
\left|A_{1} \cap A_{2}\right|=\left[\frac{120}{2 \times 3}\right]=20,\left|A_{1} \cap A_{3}\right|=\left[\frac{120}{2 \times 5}\right]=12 \\
\left|A_{1} \cap A_{1}\right|=\left[\frac{120}{2 \times 7}\right]=8,\left|A_{2} \cap A_{3}\right|=\left[\frac{120}{3 \times 5}\right]=8 \\
\left|A_{2} \cap A_{4}\right|=\left[\frac{120}{3 \times 7}\right]=5,\left|A_{3} \cap A_{4}\right|=\left[\frac{120}{5 \times 7}\right]=3 \\
\left|A_{1} \cap A_{2} \cap A_{3}\right|=\left[\frac{120}{2 \times 3 \times 5}\right]=4 \\
\left|A_{1} \cap A_{2} \cap A_{4}\right|=\left[\frac{120}{2 \times 3 \times 7}\right]=2 \\
\left|A_{1} \cap A_{3} \cap A_{4}\right|=\left[\frac{120}{2 \times 5 \times 7}\right]=1 \\
\left|A_{2} \cap A_{3} \cap A_{4}\right|=\left[\frac{120}{3 \times 5 \times 7}\right]=1 \\
\left|A_{1} \cap A_{2} \cap A_{3} \cap A_{1}\right|=[\overline{2 \times 3 \times 5 \times 7}]=0
\end{array}
$$

By formula (1) we get
$$
\begin{aligned}
& \left|A_{1} \cup A_{2} \cup A_{3} \cup A_{4}\right| \\
= & (60+40+24+17)-(20+12+8+8+5+3)+(4+2+1+1)-0=93
\end{aligned}
$$

This means that among the positive integers not exceeding 120, there are 93 numbers that are multiples of 2, 3, 5, or 7, including the numbers $2,3,5,7$ themselves, so the number of composite numbers is $93-4=89$ (numbers).
The number of prime numbers is equal to the number of 120 numbers minus the number of composite numbers and the number 1: $120-(89+1)=30$ (numbers).