Let be the set of all seven-digit numbers that can be formed using the digits 0, 1 and 2. For example, 2210222 is in , but 0210222 is NOT in .Find the number of elements in such that at least one of the digits 0 and 1 appears exactly twice in .\
[PYTHON] import itertools
def solve(): count = 0 # Iterate through all 7-digit tuples with elements 0, 1, 2 for p in itertools.product([0, 1, 2], repeat=7): # Check if first digit is not 0 if p[0] == 0: continue
c0 = p.count(0)
c1 = p.count(1)
if c0 == 2 or c1 == 2:
count += 1
print(count)
solve() [/PYTHON]
The number of such 7-digit numbers is calculated as follows: Let be the set of valid 7-digit numbers (first digit non-zero) using digits . Let be the subset of where the digit 0 appears exactly twice. Let be the subset of where the digit 1 appears exactly twice. We want to find .
-
Calculate : The digit 0 appears exactly twice. Since the first digit cannot be 0, the two 0s must be placed in the remaining 6 positions. There are ways to place the 0s. The first digit can be 1 or 2 (2 choices). The remaining 4 positions can be filled with 1 or 2 ( choices). .
-
Calculate : The digit 1 appears exactly twice.
- Case 1: The first digit is 1. One other 1 must be placed in the remaining 6 positions ( ways). The other 5 positions are filled with 0 or 2 ( choices). Count = .
- Case 2: The first digit is not 1. Since it cannot be 0, it must be 2 (1 choice). The two 1s are placed in the remaining 6 positions ( ways). The other 4 positions are filled with 0 or 2 ( choices). Count = . .
-
Calculate : 0 appears twice and 1 appears twice. The remaining digits must be 2s. The multiset of digits is .
- Case 1: First digit is 1. Remaining permutations of is .
- Case 2: First digit is 2. Remaining permutations of is . .
-
Final Result: .
\boxed{762}