【Example 7】How many five-digit numbers are divisible by 3 and contain the digit 6? How many of these have 6 as the units digit?
Solve: There are 90,000 five-digit numbers from 10000 to 99999, of which 30,000 can be divided by 3. To find the number of these that contain the digit 6, we first consider the number of those that do not contain the digit 6. We will consider each digit position:

The highest digit cannot be 0 or 6, but can only be 1, 2, 3, 4, 5, 7, 8, 9, hence there are 8 possible choices; in the thousand, hundred, and ten positions, all can be chosen except for 6, so there are 9 possible choices for each; and the last digit must be chosen such that the sum of the five digits is divisible by 3, which depends on the remainder when the sum of the first four digits is divided by 3: when the remainder is 2, the last digit can be one of 1, 4, 7; when the remainder is 1, it can be one of 2, 5, 8; when the remainder is 0, it can be one of 0, 3, 9. In any case, there are 3 possible choices. Combining the above analysis and using the multiplication principle, the number of such five-digit numbers is
$$
8 \times 9 \times 9 \times 9 \times 3=17496
$$

Subtracting this number from the total, the remaining numbers all contain the digit 6. Therefore, the number of five-digit numbers that can be divided by 3 and contain the digit 6 is
$$
30000-17496=12504 \text { (numbers) }
$$

How many of these have 6 as the last digit? We need to return to the previous analysis. For such a five-digit number to be divisible by 3, it is necessary and sufficient that the sum of its first four digits is divisible by 3. Since there are 3000 such four-digit numbers, there are also 3000 corresponding five-digit numbers.