2

I've been working through Sedgewick and Flajolet's Analytic Combinatorics and am stuck on a particular problem:

III.21. After Bhaskara Acharya (circa 1150AD). Consider all the numbers formed in decimal with digit 1 used once, with digit 2 used twice, $\dots$, with digit 9 used nine times. Such numbers all have 45 digits. Compute their sum $S$ and discover, much to your amazement, that $S$ equals 4587555960000615321908476928639999999999999999541244403999938467809152 30713600000. This number has a long run of nines. Is there a simple explanation?

I reasoned that, by grouping terms into groups of size 45 where there is one number with a 1 as the $k^{th}$ digit, two numbers with a 2 as the $k^{th}$ digit, etc. the expected value of the $k^{th}$ digit of $S$ is $(1^2 + 2^2 + \ldots + 9^2)/(1+2+\ldots+ 9 = \frac{285}{45}=\frac{19}{3})$. The number of terms in the sum is $\binom{45}{1,2,\ldots,9}$, so $S = \frac{19}{3}(1+10+\ldots+10^{45})\binom{45}{1,2,\ldots,9} = \frac{19}{3}(\frac{10^{46}-1}{9})\binom{45}{1,2,\ldots,9}$, which checks. But I have no idea where to go from here - the problem is in the chapter on multivariate generating functions, but I don't know how I could use those to find a particular string of 9's in the 10-ary expansion of a number.

2 Answers2

3

I've been thinking of this problem on and off for more than a day, and at the end the answer I've reached is very trivial and already implicit in your calculations.

Specifically, it's just this simple fact:

Lemma: If a number $A$ has $n$ digits, then for $m > n$, the number $A(10^m - 1)$ has a run of $m-n$ nines, namely in the positions having place value $10^n$ to $10^{m-1}$.

The proof is simple: $A(10^m - 1) = A(10^m) - A$, and the subtraction looks like

  abc...xyz000...000000...000
-                   abc...xyz
  ---------------------------
  abc...xyZ999...999jkl...pqr

Or to write it formally, observe that $$A(10^m-1) = B 10^n + (10^n - A)$$ where $$B = (A-1)10^{m-n} + (10^{m-n} - 1),$$ so the digits in places $n$ to $m-1$ (counting from the right, starting with $0$) of $A(10^m - 1)$ are the last $m-n$ digits of $B$, which form the number $10^{m-n} - 1$ which is a string of $m-n$ nines.

Now of course for the sum $S$ of this problem, if we write down all $N$ numbers one below the other and let $C$ be the sum of the digits in a single column, then (as both you and Ross's answer calculated), we have $$S = C(1 + 10 + 10^2 + \dots + 10^{44}) = C\left(\frac{10^{45} - 1}{10 - 1}\right),$$ $$C = N\left(\frac{1^2 + 2^2 + \dots + 9^2}{1 + 2 + \dots + 9}\right),$$ $$N = {45 \choose 1, 2, \cdots, 9} = \frac{45!}{1!2!\cdots9!}.$$

Doing the calculations gives $C = 412880036400055378971762923577600000$, which ends in five zeroes (and is divisible by $9$ -- both facts you can prove by looking at powers of $3$, $2$ and $5$ in the expression for $N$), so with $A = C/(9 \times 10^5)$ we have $$S = C\left(\frac{10^{45} - 1}{9}\right) = A(10^{45}-1) \times 10^{5},$$ and as $A$ is a $30$-digit number, this means that $N$ has a run of nines from position $30+5$ to position $45-1+5$, which is precisely what is observed.

ShreevatsaR
  • 42,279
2

Not a generating function approach, but I would just calculate how many numbers there are. The digits will appear in their proper proportion ($\frac 1{45} 1's, \dots \frac 9{45} 9's$), so if there are $N$ numbers the sum will be $\frac N{45}(1^2+2^2+\dots 9^2)(\frac {10^{45}-1}9)$ where the last factor is the number with $45\ 1's$

To evaluate $N$, we can choose where the $9's$ go in $45 \choose 9$ ways, where the $8's$ then go in $36 \choose 8$ ways and so on. So we have $N={45 \choose 9}{36 \choose 8}{28 \choose 7}\dots {1 \choose 1}$ and the total sum is$$\frac 1{45}{45 \choose 9}{36 \choose 8}{28 \choose 7}\dots {1 \choose 1}\frac {9\cdot 10\cdot 19}6(\frac {10^{45}-1}9)=\\\frac 1{45}\cdot 65191584694745586153436251091200000\cdot 285(\frac {10^{45}-1}9)=\\45875559600006153219084769286399999999999999954124440399993846780915230713600000$$ This is not going to give a nice explanation of the run of nines.

Ross Millikan
  • 383,099
  • I think your $\binom{45}{9}\binom{36}{8}\binom{28}{7}\cdots\binom{1}{1}$ is the same as the OP's multinomial coefficient $\binom{45}{1, 2, \dots, 9} = \frac{45!}{1!2!\cdots9!}$, correct? – ShreevatsaR Feb 10 '14 at 06:44
  • That is, the OP's calculation as $$S = \frac{1^2 + 2^2 + \dots + 9^2}{1 + 2 + \dots + 9}(1 + 10 + 10^2 + \dots + 10^{45}) N$$ and your calculation as $$S = \frac{N}{45}(1^2 + 2^2 + \dots + 9^2)(\frac{10^{45}-1}{9})$$ appear to be identical (as is the $N$ calculated), which is a good independent confirmation. – ShreevatsaR Feb 10 '14 at 06:57