[Math] the probability that 5 digit number divisible by 6

divisibilityprobability

The main constraint is that each digit can only take digits from $\{1, 2, 3, 4, 5\}$. So the sample space will be $5^{5}$.

What is the probability that a random number taken from this sample space will be divisible by $6$?

Thanks.

Best Answer

$$\color{red}{416/3125}=0.13312. $$ The last digit must be $2$ or $4$, this happens with probability $2/5$. The sum of the four other digits must be $\pm1\pmod{3}$, according to the last digit being $2$ or $4$. Since both events have the same probability, the answer is $2/5$ times the probability that the sum $s$ of four digits is $1\pmod{3}$, that is, $s=-2$ or $s=+1$ or $s=+4$.

$s=+4$ corresponds to $+1,+1,+1,+1$, with probability $2^4/5^4$.

$s=+1$ corresponds to $0,0,0,+1$, or $0,+1,+1,-1$ in whatever order. In the first case, one must place the $+1$, thus $4$ cases, with probability $2/5^4$ each. In the second case, one must place the $0$ and the $-1$, thus $12$ cases, with probability $2^3/5^4$ each.

$s=-2$ corresponds to $+1,-1,-1,-1$, thus $4$ cases, with probability $2^4/5^4$ each, or to $0,0,-1,-1$, thus $6$ cases, with probability $2^2/5^4$ each.

Summing up, the answer is $(2/5)\cdot(2^4+4\cdot2+12\cdot2^3+4\cdot2^4+6\cdot2^2)/5^4$.