# How many n-digit numbers contain at least one 2 and at least one 3, but no 7’s?

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.

= 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)

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$.

• How can I visualise this with a Venn Diagram? – B.A. Apr 5 '14 at 6:51
• The easiest is to let the "universe" be the numbers that are missing a $7$. Then draw two intersecting ovals $X$ and $Y$, where $X$ is represents the numbers in our universe that have no $2$, and $Y$ represents the numbers in our universe that have no $3$. We want to count the numbers in our universe that are outside $X\cup Y$. The number $2b-c$ counts $X\cup Y$. – André Nicolas Apr 5 '14 at 6:57
• You are welcome. I am sure you can compute $a$, $b$, and $c$. For example $b=(7)(8^{n-1})$. – André Nicolas Apr 5 '14 at 7:13
• Yep. I got 8*9^(n-1) - 2*7*8^(n-1) + 6*7^(n-1) – B.A. Apr 5 '14 at 7:20