1

From, we have

Determine the number of positive integers $x$, where $x$ is less than equal to $9,999,999$ and the sum of the digits in x is $31$.

I got $512365$, with source of my programming solution at here.

I tried to do an analysis of my answer to see if it was probably correct. It was divisible by 7, which was a start. I then decided to try to estimate the number of solutions to the problem.

In general, we should get around 4.5 per digit, or a total of 31.5, which is quite close to the sum we are searching for, actually. Assuming that the sum of digits is normally distributed (my big question: is it?), we should get around 40%*9,999,999 , which is around 4 million, greatly disagreeing with my answer. What am I doing wrong?

leonbloy
  • 63,430
inkyvoyd
  • 13
  • 3

1 Answers1

1

We take at random a number of seven digits, so each digit is a iid discrete uniform variable $X$ in $0\ldots9$, so $E(X)=9/2$, $\sigma_x^2 = 99/12$.

The sum of digits, then, $Z = \sum_{i=1}^7 X_i$ has $E(Z)= 7 \; E(X)= 31.5$ and $\sigma_z^2 = 7 \sigma_x^2 = 57.75$. The sum of 7 uniforms can be roughly approximated by a gaussian, with those moments. Further, we can approximate $31 \approx 31.5$ and

$$P(Z=E(Z)) \approx \int_{\mu_z -1/2}^{\mu_z+1/2} N(x) \, dx \approx N(\mu_z) = \frac{1}{\sqrt{2 \pi \sigma_z^2}} \approx 0.0524969$$

where $N(x)$ is a gaussian density with parameters $\mu_z$, $\sigma_z^2$.

Hence, the total count is given by $10^7 \times 0.0524969= 524969$ - not so far from your exact 512365.

Better approximations are possible, of course (eg)

leonbloy
  • 63,430