What's wrong with my method of counting the number of $7$s under $1000000$?

51 Views Asked by At

I need to find the number of $7$s if we write all the numbers from $1$ to $1000000$(so $77$, for example, counts as two $7$s and not one).

Here's what I did:

I split the problem into $7$ sections:

The number of $7$s in numbers with one seven: $\displaystyle \binom{7}{1}$$*$ $9^6$(number of ways to place one $7$ times the number of possible numbers we could make with each displacement. Note that leading zeros wouldn't be a problem since they would result in numbers with less than $7$ digits which we need)

The number of $7$s in numbers with two sevens: $\displaystyle\binom{7}{2} * 9^5 * 2$(same logic, but we multiplied it by $2$ since there's two sevens)

...

So my answer would be $\sum_{i=1}^7 \displaystyle \binom{7}{i}9^ii$ but my textbook says the right answer is $600000$. I do understand its solution but I don't know why mine is wrong.

Thanks in advance!

2

There are 2 best solutions below

0
On BEST ANSWER

You're counting $7$ digit numbers but you only need $6$.

1
On

One. the numbers $0$ to $999999$ (as $1000000$ doesn't have any $7$) have $6$ digits. Not seven.

Three somehow you went from the power being $6-i$ to $i$.

$\sum_{k=1}^6 {6\choose k}9^{6-k}*k = 6*59049*1 + 15*6561*2 + 20*279*3 + 15*81*4 + 6*9*5 + 1*1*6=600000$

But why break it into seven cases?

If we count the number of times $7$ appears in the $n$ position there are $10^5$ ways the other digits can be. So a $7$ will appear in the $n$ position $10^5$ times. So the total number of $7$s that appear in any and all of the six positions will be $6*10^5$.

Interesting result though $\sum_{k=1}^n {n \choose k}(b-1)^{n-k}*k = n*b^{n-1}$ apparently.

Think you can prove that or give an argument why it'd be so?