2

Find number of positive integers less than $10^8$ with digit sum of $24$.

I thought I could use the argument $a+b+c+d+e+f+g+h = 24$ and then make the substitution $x_1 = 9-a, x_1 = 9-b,\ldots,x_8 = 9-h\ldots$ but then that would also count negative values of $a,b,\ldots,h$ so I am thinking there is a better way to count this. Or maybe my way could work and we subtract away the negative cases?

Puzzled417
  • 7,126
  • Not sure why you'd do that substitution. You want $0\leq a,b,c,\dots\leq 9$. – Thomas Andrews Jan 16 '16 at 23:40
  • Most of the numbers less than $10^8$ have eight digits. (The number $10^8$ itself has nine digits.) If your sum $a+b+c+d+e+f+g$ is a sum of digits $a, b, c, d, e, f, g$, then you are missing a digit. And what does $10 - a$ have to do with anything, what is $x_1$ for, etc. ... none of that part makes any sense at all. – David K Jan 16 '16 at 23:41
  • Yes, you are right I made typos. And the substitutions I thought were going to help as for any positive $x_n$ we get our correct solutions for $a,b,...$ except that some may be negative. Without the substitutions some may be greater than $9$. – Puzzled417 Jan 16 '16 at 23:42
  • Highly relevant: http://math.stackexchange.com/questions/881202/how-many-10-digit-number-exists-that-sum-of-their-digits-is-equal-to-15 and http://math.stackexchange.com/questions/653825/determine-the-number-of-positive-integer-x-where-x-9-999-999-and-the-sum-of-th – David K Jan 17 '16 at 01:55
  • Here is a problem where a variable change (in this case $z_n = 4 - x_n$) makes sense: http://math.stackexchange.com/questions/508026/inclusion-exclusion-principle That technique is useful when the sum to achieve is so large that you must have multiple digits at the highest value. For example, if the sum of your $8$ digits had to be $63$ then $x_1=9-a$, $x_2=9-b$, etc. would change it to the simpler problem of an $8$-digit number whose sum of digits is $9$. But what you did was to change the sum of $8$ digits from $24$ to $48$, that is, you made the problem more complicated. Don't do that. – David K Jan 17 '16 at 14:55

1 Answers1

3

Generating function approach.

You want the coefficient of $x^{24}$ in:

$$\begin{align}(1+x+x^2+x^3+x^4+x^5+x^6+x^7+x^8+x^9)^{8} &= \left(\frac{1-x^{10}}{1-x}\right)^{8}\\ &=(1-x^{10})^8\sum_{k=0}^\infty\binom{k+7}{7}x^k \end{align}$$

We can ignore the higher terms of $(1-x^{10})^8 = 1-8x^{10}+28x^{20}-\cdots$ because they do no contribute to $x^{24}$.

So you get: $$\binom{24+7}{7}-8\binom{14+7}{7}+28\binom{4+7}{7}$$

This can also be seen as an inclusion-exclusion result. $\binom{24+7}{7}$ is the number of ways of writing $24$ as the sum of eight non-negative integers. For each position, we subtract the $\binom{14+7}{7}$ solutions where that position is $10$ or greater. But then we've subtracted some of the sums twice, so we have to add back the cases where two of the values are $10$ or greater.

Thomas Andrews
  • 186,215
  • How does = $\left(\frac{1-x^{10}}{1-x}\right)^{8} =(1-x^{10})^8\sum_{k=0}^\infty\binom{k+7}{7}x^k$? – Puzzled417 Jan 16 '16 at 23:58
  • In general: $\frac{1}{(1-x)^m} = \sum \binom{k+m-1}{k}x^k$. Or you can think of this in terms of the related generating function: $$\frac{1}{(1-x)^m} = (1+x+x^2+\dots)^m$$ so the coefficient of $x^k$ is the number of partitions of $k$ into $m$ non-negative integer, which is $\binom{k+m-1}{m}$. – Thomas Andrews Jan 17 '16 at 00:01
  • You say "$\binom{24+7}{7}$ is the number of ways of writing $24$ as the sum of non-negative integers." How? – Puzzled417 Jan 17 '16 at 00:06
  • Sorry, that should have said "as the sum of $8$ non-negative integers." It is a standard result sometime called "Stars and Bars," due to the way it is proven. Eating, will fix answer a moment. – Thomas Andrews Jan 17 '16 at 00:08
  • I don't really get the inclusion-exclusion reasoning. How did you know to add and subtract those amounts? Is there a way to visualize it? – Puzzled417 Jan 17 '16 at 00:13
  • I don't like inclusion-exclusion proofs, because they get tangled quickly, but the general page on wikipedia shows the formula. You are trying to subtract the partitions that $\binom{24+7}{7}$ shouldn't count - where one of the values is $10$ or more. Letting $A_i$ be the set of partitions where the $i$th position is $10$ or more and applying the standard inclusion exclusion on those sets lets you count $\bigcup A_i$, which you then want to subtract. I this case, the inclusion/exclusion is simple, because $A_i\cap A_j$ is the same for all $i\neq j$, and $A_i\cap A_j\cap A_k=\emptyset$. – Thomas Andrews Jan 17 '16 at 00:22
  • Do you mind writing out the sets equation like $(A \cup B \cup \cdots) = ...$? – Puzzled417 Jan 17 '16 at 01:29
  • "Letting $A_i$ be the set of partitions where the $i$th position is $10$ or more," the union $A_1\cup A_2\cup\cdots$ becomes ${\text{$8$ numbers with sum $24$ where $a\geq 10$}}\cup{\text{$8$ numbers with sum $24$ where $b\geq 10$}}\cup\cdots$. – David K Jan 17 '16 at 15:05