[Math] How many natural numbers are there less than $90000$ that have the sum of digits equal to $8$

combinatorics

I want to find out how many natural numbers are there less than $90000$ that have the sum of digits equal to $8$.

$x_1+x_2+x_3+x_4+x_5=8$ where $5>x_i>0$.

Relaxing $5>x_i$ for now we get $\binom{7}4$ number of solutions.

Now let $x_1>5$.Clearly there are no solutions for this. So is the answer $\binom{7}4$ ?

Best Answer

I also got 35. Did it the old fashioned way so there may be an error. Note we can't pick any digit to be 5 either because there would be 4 more digits to pick each of which must be at least 1 so the total sum becomes > 8.

1) Pick the first digit to be 4 then all other digits must be 1

4 1 1 1 1

there are 5 positions where 4 can go so there are 5 of these numbers.

2) Pick the first digit to be 3 then we cannot pick another 3 because we would go over. Pick the second digit 2

3 2

now , all remaining digits must be 1

3 2 1 1 1

keeping 3 fixed , there are four positions for 2. Since there are five positions for 3 we use the multiplication principle to get 5×4 = 20 of these numbers.

3) Pick the first digit to be 2. There is no need to pick 3 as any digit because that has been done already above at 2). Pick the second digit to be 2

2 2

the sum is already 4. now there are three digits remaining to pick and one of them must be 2

2 2 2

we are forced to pick 1 for the remaining digits

2 2 2 1 1

let's work with the 1's switching their position. We can use the same argument as before to get 5×4 = 20 but now we divide by two because the digits switching position are equal. There are 10 of these numbers.

There is no need to pick the first digit to be 1 because all possible configurations have been counted already. We are done counting.

5 + 20 + 10 = 35