5. In the number $2 * 0 * 1 * 6 * 0 *$, each of the 5 asterisks needs to be replaced with any of the digits $0,1,2,3,4,5,6,7,8$ (digits can repeat) so that the resulting 10-digit number is divisible by 18. In how many ways can this be done?
Answer: 3645.

Solution. For a number to be divisible by 18, it is necessary and sufficient that it is divisible by 2 and by 9. To ensure divisibility by 2, we can choose the last digit from the available options as $0, 2, 4, 6$ or 8 (5 ways).

To ensure divisibility by nine, we proceed as follows. Choose three digits arbitrarily (this can be done in $9 \cdot 9 \cdot 9$ ways), and select the fourth digit so that the sum of all the digits of the number is divisible by 9. Since these digits give all possible remainders when divided by $9 (0, 1, 2, \ldots, 8)$, and each remainder occurs exactly once, the last digit can be chosen in one way.

Applying the rule of product, we get that there are $5 \cdot 9 \cdot 9 \cdot 9 \cdot 1 = 3645$ ways.