Digit Sum Invariant

Find the number of integers between 1 and 1 0 6 10^6 such that the sum of their digits is equal to 12.


The answer is 6062.

This section requires Javascript.
You are seeing this because something didn't load right. We suggest you, (a) try refreshing the page, (b) enabling javascript if it is disabled on your browser and, finally, (c) loading the non-javascript version of this page . We're sorry about the hassle.

2 solutions

Christopher Boo
Nov 10, 2016

Relevant wiki: Integer Equations - Stars and Bars

Let the number be

N = d 1 d 2 d 3 d 4 d 5 d 6 N = \overline{d_1d_2d_3d_4d_5d_6}

where 0 d i < 10 0 \leq d_i < 10 represents each digit. Note that leading 0 0 's is allowed as N N can be any number between 1 1 and 1 0 6 10^6 . For example, 34 34 will be encoded as 000034 000034 .

We want the sum of digits equal to 12. In other words,

d 1 + d 2 + d 3 + d 4 + d 5 + d 6 = 12 d_1+d_2+d_3+d_4+d_5+d_6 = 12

The number of combinations of ( d 1 , d 2 , , d 6 ) (d_1, d_2, \dots , d_6) can be computed using the stars and bars technique, which gives ( 17 5 ) = 6188 {17 \choose 5} = 6188 .

However, there are cases where d i 10 d_i\geq 10 . We should remove these cases. Furthermore, there cannot be cases such that more than one digit is greater or equal to 10 because their sum will exceed 12. Hence the cases for each digit greater or equal to 10 is mutually exclusive. Suppose d 1 10 d_1 \geq 10 , then we transform d 1 = d 1 10 d_1'=d_1-10

d 1 + 10 + d 2 + d 3 + d 4 + d 5 + d 6 = 12 d 1 + d 2 + d 3 + d 4 + d 5 + d 6 = 2 d_1' + 10 + d_2 + d_3 + d_4 + d_5 + d_6 = 12 \rightarrow d_1' + d_2 + d_3+d_4+d_5+d_6 = 2

Again by using the stars and bars technique, the number of combinations is ( 7 5 ) = 21 {7 \choose 5}=21 . Apply the same to all 6 digits and we have a total of 21 × 6 = 126 21 \times 6 = 126 such cases. Hence the answer is

6188 126 = 6062 6188-126 = 6062

loved the way you excluded those extra cases .

space sizzlers - 4 years, 6 months ago

Log in to reply

Thanks! It depends on the setup; the extra cases are easy to handle. If the digit sum exceeds 20, then it might be painful.

Christopher Boo - 4 years, 6 months ago
Peter Macgregor
Nov 18, 2016

The solution is equal to the coefficient of x 12 x^{12} in the expression ( x 0 + x 1 + x 2 + x 3 + x 4 + + x 9 ) 6 (x^0+x^1+x^2+x^3+x^4+ \dots +x^9)^{6}

You can make wolfram-alpha do the work by entering

expand (1+x+x^2+x^3+x^4+x^5+x^6+x^7+x^8+x^9)^6

and then picking out the coefficient of x 12 x^{12} which is 6062 \boxed{6062}

Explanation

A little thought shows that the problem is equivalent to the number of compositions of 12 into 6 heaps with no heap being greater than 9, and with the possibility of some heaps being zero. The relationship between compositions and binomial-like coefficients is given here .

Great work!

Mayank Jain - 4 years, 6 months ago

0 pending reports

×

Problem Loading...

Note Loading...

Set Loading...