How many 8 digit numbers are there, such that they are divisible by 9 and all of the digits are distinct? 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.
 A: For any collection of $8$ digits $a_1\dots a_8$, either all permutations of them will yield one number that will be divisible by $9$ or none of them will. This is because a number is divisible by $9$ if and only if the sum of its digits is divisible by $9$.
So, the first answer you need to get is:

How many collections of $8$ distinct digits are there if their sum must be divisible by $9$?

To answer this question, first note that the sum of the available $10$ digits is $45$. Now, you have to take $2$ of the numbers away, and the sum must be divisible by $9$. You can see that:


*

*The minimum sum you can remove is $1$

*The maximum is $17$


Which means the new sum will be somewhere between $28$ and $44$, and there is only one number divisible by $9$ in that range.

After you answer the first question, the rest should be easy pickings. For each collection of $8$ digits, there are $8!$ numbers they produce. The only thing you need to be careful is whether the collection includes $0$ or not. If it does, $7!$ of the resulting numbers (those with $0$ in their first place) will be $7$ digit numbers, while the remaining $7\cdot 7!$ will be $8$ digit numbers.
A: 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$$
