Question
Question: Let S be the set of all seven-digit numbers that can be formed using the digits 0, 1 and 2. For exam...
Let S be the set of all seven-digit numbers that can be formed using the digits 0, 1 and 2. For example, 2210222 is in S, but 0210222 is NOT in S. Then the number of elements x in S such that at least one of the digits 0 and 1 appears exactly twice in x, is equal to _____________.

762
Solution
Let S be the set of all seven-digit numbers that can be formed using the digits 0, 1 and 2. A seven-digit number must have the first digit non-zero. The digits allowed are 0, 1, 2. So, the first digit can be 1 or 2. The remaining six digits can be 0, 1, or 2. The total number of elements in S is 2×36=2×729=1458.
We are looking for the number of elements x in S such that at least one of the digits 0 and 1 appears exactly twice in x. Let A be the set of numbers in S where the digit 0 appears exactly twice. Let B be the set of numbers in S where the digit 1 appears exactly twice. We want to find ∣A∪B∣=∣A∣+∣B∣−∣A∩B∣.
To find ∣A∣, we count the number of 7-digit numbers in S with exactly two 0s. The digits used are two 0s, and five digits from {1, 2}. The first digit cannot be 0. Case 1: The first digit is 1. The first digit is 1. We need to place two 0s and four digits from {1, 2} in the remaining 6 positions. The number of ways to choose the positions for the two 0s from the remaining 6 positions is (26). The remaining 4 positions must be filled with digits from {1, 2}. There are 24 ways. Number of elements in this case = (26)×24=15×16=240.
Case 2: The first digit is 2. The first digit is 2. We need to place two 0s and four digits from {1, 2} in the remaining 6 positions. The number of ways to choose the positions for the two 0s from the remaining 6 positions is (26). The remaining 4 positions must be filled with digits from {1, 2}. There are 24 ways. Number of elements in this case = (26)×24=15×16=240.
Total number of elements in S with exactly two 0s is ∣A∣=240+240=480.
To find ∣B∣, we count the number of 7-digit numbers in S with exactly two 1s. The digits used are two 1s, and five digits from {0, 2}. The first digit cannot be 0. Case 1: The first digit is 1. The first digit is 1. We need to place one more 1 and five digits from {0, 2} in the remaining 6 positions. The number of ways to choose the position for the second 1 from the remaining 6 positions is (16). The remaining 5 positions must be filled with digits from {0, 2}. There are 25 ways. Number of elements in this case = (16)×25=6×32=192.
Case 2: The first digit is 2. The first digit is 2. We need to place two 1s and four digits from {0, 2} in the remaining 6 positions. The number of ways to choose the positions for the two 1s from the remaining 6 positions is (26). The remaining 4 positions must be filled with digits from {0, 2}. There are 24 ways. Number of elements in this case = (26)×24=15×16=240.
Total number of elements in S with exactly two 1s is ∣B∣=192+240=432.
To find ∣A∩B∣, we count the number of 7-digit numbers in S with exactly two 0s and exactly two 1s. The digits used are two 0s, two 1s, and three 2s (since 2+2+3=7). The first digit cannot be 0. Total permutations of two 0s, two 1s, and three 2s is 2!2!3!7!=2×2×65040=245040=210. We subtract the number of such arrangements that start with 0. If the first digit is 0, the remaining 6 digits must contain one 0, two 1s, and three 2s. The number of permutations of these 6 digits is 1!2!3!6!=1×2×6720=12720=60. Number of elements in S with exactly two 0s and exactly two 1s is ∣A∩B∣=210−60=150.
Using the principle of inclusion-exclusion: ∣A∪B∣=∣A∣+∣B∣−∣A∩B∣=480+432−150=912−150=762.
The number of elements x in S such that at least one of the digits 0 and 1 appears exactly twice in x is 762.
The final answer is 762.