[Math] How many 8 digit numbers are there, such that they are divisible by 9 and all of the digits are distinct

permutations

What I'm looking for here is not the answer, but a way to approach this question to get to the answer.

Actually, there are some answers where this question was posted, but they are hard to understand. I do see that apparently the answer lies in the fact that you can sum pairs of numbers that add up to 9. E.g., if we have the set {0, 1, 2, 3, 4, 5, 6, 7, 8, 9}, you can sum (0 + 9 = 9), (1 + 8 = 9), …, (9 + 0 = 9). Also, not summing them but pairing them also produces a number that is divisible by 9 (09), (18), …, (90). Seems like magic 🙂 But how to go from here?

Please if you could, explain in simplest terms possible.

Best Answer

Observe that $0+1+2+3+4+5+6+7+8+9=45$.

We need to remove $2$ digits, while keeping the sum of the remaining $8$ digits divisible by $9$.

The options are:

  • Remove $[0,9]$ and keep $[1,2,3,4,5,6,7,8]$
  • Remove $[1,8]$ and keep $[0,2,3,4,5,6,7,9]$
  • Remove $[2,7]$ and keep $[0,1,3,4,5,6,8,9]$
  • Remove $[3,6]$ and keep $[0,1,2,4,5,7,8,9]$
  • Remove $[4,5]$ and keep $[0,1,2,3,6,7,8,9]$

Now, simply add up the amount of $8$-unique-digit numbers for each option:

  • With $[1,2,3,4,5,6,7,8]$ we can generate $8!=40320$ such numbers
  • With $[0,2,3,4,5,6,7,9]$ we can generate $8!-7!=35280$ such numbers
  • With $[0,1,3,4,5,6,8,9]$ we can generate $8!-7!=35280$ such numbers
  • With $[0,1,2,4,5,7,8,9]$ we can generate $8!-7!=35280$ such numbers
  • With $[0,1,2,3,6,7,8,9]$ we can generate $8!-7!=35280$ such numbers

Hence the total amount of $8$-unique-digit numbers divisible by $9$ is:

$$40320+35280+35280+35280+35280=181440$$