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 .\
[THOUGHT]
We need to count seven‑digit numbers using only digits {0,1,2} with the first digit non‑zero.
Total such numbers: (2 \cdot 3^6 = 1458).
We must count numbers where at least one of the digits 0 or 1 appears exactly twice.
Let
- (N_0) = numbers with exactly two 0’s (digit 1 may appear any number of times).
- (N_1) = numbers with exactly two 1’s (digit 0 may appear any number of times).
- (N_{01}) = numbers with exactly two 0’s and exactly two 1’s (so three 2’s).
The desired count is (N = N_0 + N_1 - N_{01}) (inclusion–exclusion).
For a fixed multiset of digits ((a,b,c)) where (a) = count of 0’s, (b) = count of 1’s, (c) = count of 2’s, the number of distinct strings of length 7 is the multinomial coefficient
[ \frac{7!}{a!,b!,c!}. ]
If the first digit is forced to be non‑zero, we subtract the strings that start with 0.
When (a>0), those are
[ \frac{6!}{(a-1)!,b!,c!}. ]
Thus for each case we sum over all possible ((a,b,c)) satisfying the required counts.
We will compute (N_0), (N_1), and (N_{01}) using Python. [/THOUGHT] [PYTHON] import math
def count_strings(a, b, c): """Number of 7‑digit strings with a zeros, b ones, c twos, first digit ≠ 0.""" total = math.factorial(7) // (math.factorial(a) * math.factorial(b) * math.factorial(c)) if a > 0: # strings with leading zero leading_zero = math.factorial(6) // (math.factorial(a-1) * math.factorial(b) * math.factorial(c)) return total - leading_zero else: return total
Total numbers in S (sanity check)
total_S = 2 * (3**6) print("Total S =", total_S)
N0: exactly two 0's (a=2), b from 0 to 5, c = 7 - a - b
N0 = 0 for b in range(0, 6): # b can be 0..5 because a=2, c >=0 c = 7 - 2 - b N0 += count_strings(2, b, c)
N1: exactly two 1's (b=2), a from 0 to 5, c = 7 - a - 2
N1 = 0 for a in range(0, 6): # a can be 0..5 because b=2, c >=0 c = 7 - a - 2 N1 += count_strings(a, 2, c)
N01: exactly two 0's and exactly two 1's (a=2, b=2, c=3)
N01 = count_strings(2, 2, 3)
print("N0 =", N0) print("N1 =", N1) print("N01 =", N01)
Desired count
N = N0 + N1 - N01 print("Desired count =", N) [/PYTHON]
[THOUGHT] The Python computation verified the counts: 480 numbers with exactly two 0's, 432 with exactly two 1's, and 150 with both. Applying inclusion-exclusion gives 480 + 432 - 150 = 762 valid numbers where at least one of 0 or 1 appears exactly twice. [/THOUGHT] \boxed{762}