How many integers from $43523$ to $93107$ contain the digit $7$ at least once?

I know that if we had $43000$ to $93000$, we would subtract integers that do not contain digit $7$ from the total number: $50000 - (5\times9\times 9\times 9 \times 9)$

But how to do it with the given numbers?

  • 3
    $\begingroup$ Try using inclusion-exclusion principle $\endgroup$ – user262291 Apr 29 '16 at 5:35
  • $\begingroup$ The same way. Figure how many between 40000 and 43000, then between 43000 and 43500, between 43500 and 43520. And the same for the larger numbers. $\endgroup$ – fleablood Apr 29 '16 at 5:37

First idea: if you want the number of something from $42523$ through $93107$, it may be easier to count the ones from $0$ through $93107$ and subtract the ones from $0$ through $42522$. Let $N(n)$ be the number of numbers up to $n$ that contain at least one $7$. You want $N(93107)-N(43522)$. It helps to prefix the numbers with zero so all numbers have five digits. Second idea: $N(93107)$ consists of all the numbers that start with $7$, which is $70000$ through $79999$, plus all the others that contain at least one $7$. For the ones that start with $0$ through $8$, that is $8$ times as many as the four digit numbers that contain at least one $7$. This suggests a recursive algorithm. I leave the problem that you only want some of the numbers that start with $9$ to you. The idea is the same.


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.