[Math] How many n-digit numbers contain at least one 2 and at least one 3, but no 7’s

combinatorics

Additional rule: each digit is one of $\{0,1,2…9\}$ and the first digit is nonzero.

I think this question isn't hard, I just don't seem to be clear about the question.

My interpretation: How many numbers which don't contain 7 have at least a 2 AND have at least a 3.

My answer:

= all non-7-containing numbers – non-7-containing numbers that have no 2 and no 3

= $8*9^{n-1} – 6*7^{n-1}$ (answer is currently wrong)

Best Answer

We use Inclusion/Exclusion.

It is easy to count the numbers that are missing a $7$. Suppose there are $a$ of them.

Call such a number bad if it is also missing $2$ or $3$ or both.

It is not hard to count the numbers that miss $7$ and $2$. Suppose there are $b$ of them.

Then there are $b$ numbers that miss $7$ and $3$.

But $b+b$ double-counts the numbers that miss $7$, $2$, and $3$. Call the number of such numbers $c$.

Then the number of bad numbers is $2b-c$, so our count is $a-2b+c$.