[Math] How many positive integers between 0 and 1,000,000 contain the digit 9

combinatorics

In the example, it says that its easier to count the number of integers that do not contain the digit 9

what i did is, since its from $0$ to $1{,}000{,}000$ i can simply say its to $999{,}999$
and for 6 digits there are 8 choices of numbers, so $6^8$.
now subtract that from $1{,}000{,}000$ and we get $679{,}616$ as the numbers that contain the digit $9$, is that correct?

Best Answer

You have six slots. In each slot you can place any digit between 0 and 9 (ten possibilities). This generates all $10^6$ possible numbers from 0 to $999,999$ (ignoring leading zeros as necessary). To generate a number that doesn't contain a nine, there are only nine possibilities for each slot (namely, $0$ through $8$), yielding $9^6$. So the total number of integers between zero and $999,999$ that do contain the digit nine is $10^6-9^6$. This is the same as the number of positive integers between 0 and a million that do so.