# Formation of a 7 digit number using 3 digits with given condition

The number of different 7 digit numbers that can be written using only three digits $1,2,3$ under the condition that the digit 2 occurs exactly twice in each number is?

My Attempt:
Total number of digits possible = $3^7$

Then, I would subtract all the digits with no or single 2 occurrences.

No. digits in which no 2 occur is $2^7$

No. digits in which 2 occur once is $\binom712^6$

So total unfavorable numbers are $2^7+\binom712^6$

So total favorable numbers are $3^7 - 2^7-\binom712^6$

However, when solved, this turns out to be a wrong answer.

Can anyone help?

## 2 Answers

You forgot to subtract the numbers in which 2 appears three or more times. Here is a correct approach:

• Select the locations of the 2s: $\binom72=21$ ways
• Fill the remaining five slots with 1s and 3s: $2^5=32$ ways

Hence there are $21\cdot32=672$ admissible numbers.

• I subtracted the the No.of digits that contained 3 or more 2s. But I am still getting the wrong answer. – Piano Land Mar 11 '18 at 10:24
• @PianoLand do your calculations more carefully:$$3^7-\binom702^7-\binom712^6-\binom732^4-\binom742^3-\binom752^2-\binom762^1-\binom772^0=672$$ – Parcly Taxel Mar 11 '18 at 10:56
• Sorry for wasting your precious time. – Piano Land Mar 11 '18 at 11:00

The 7-digit number has exactly two digits $2$.

Let's say the number is $\overline{22cdefg}$; $\overline{2b2defg}$; $\overline{2bc2efg}$;...

The number of cases we can put exactly two digits (out of $7$ digits) are $2$ is: $6+5+4+3+2+1=21$ cases.

For each case, the remaining $5$ digits can be either $1$ or $3$, so the number of ways for each case is: $2^5=32$ ways.

The number of favorable numbers is: $21 \times 32 =672$ numbers.