How many $5$ digit numbers that are divisible by $6$ can be written by using $\{0,1,2,3,4,5\}$ if repetition is allowed?

How many distinct $$5$$ digit numbers that are divisible by $$6$$ can be written by using $$\{0,1,2,3,4,5\}$$ if repetition is allowed?

We know that the last digit must be either $$0$$ or $$2$$ or $$4$$ . However, I am stuck in divisibility by $$3$$. At first glance, I thought to use an exponential generating function, but I realize that it will be brute force, as well.

Hence, I am looking for nice approach to this question.

You can see the same question but not repetition allowed : Find the number of 5-digit number divisible by 6 which can be formed using $0,1,2,3,4,5$ if repetition of digits is not allowed.

• are you familiar with the "rule of 3"? $M$ is a multiple of $3$ if and only if the sum of the digits is a multiple of $3$. Are you familiar with that? Jun 12, 2021 at 5:20
• @fleablood yeap , but i do not know how to satify it in question . it is long process for trial
– user873477
Jun 12, 2021 at 5:22
• If the $4$ of the $5$ digits are $a,b,c,d$ then the fifth digit, $e$ must be such that $e \equiv a+b+c+d \pmod 6$. Now the options are the $e \equiv 0,1,$ or $2\pmod 3$ (how many of each) and $a+b+c+d \equiv 0,1$ or $2 \pmod 3$ ... can you figure. (This is much easier than the question without repetiion by the way.) Jun 12, 2021 at 5:25
• Well, you have the last digit must be $0,2$ or $4$. and what are the options for the next three digits. Now gave any set of for digits what choices do you have to make the last digit makes it divisible by $3$. Jun 12, 2021 at 5:27
• Note that the set $S = \{0,2,4\}$ contains exactly one element congruent to $1 \pmod{3}$, one element congruent to $2 \pmod{3}$, and one element congruent to $3 \pmod{3}.$ Note also that the leftmost digit (arguably) can't be $0$. Jun 12, 2021 at 5:36

• can we generalize this method ? For example let $S = \{0,1,2,3,4,5,6,7,8,9\}$. Then , how many $8$ digit distinct number are there which are divisible by $7$ ? Is the answer equal to $9 \times 10 ^6$?