5. Form an n-digit number using the digits 1,2,3, requiring that each of 1,2,3 appears at least once in the n-digit number. The total number of such n-digit numbers is .
Official solution
5. 3n−3⋅2n+3.
Let the set of all n-digit numbers composed of the digits 1,2,3 be denoted as I, and the sets of all n-digit numbers in I that do not contain the digits 1,2,3 be denoted as A1,A2,A3, respectively. Then ∣I∣=3n,∣A1∣=∣A2∣=∣A3∣=2n,∣Ai∩Aj∣=1, (1⩽i<j⩽3),∣A1∩A2∩A3∣=0, thus A1∪A2∪A3=∣I∣−∣A1∣−∣A2∣−∣A3∣+∣A1∩A2∣+∣A2∩A3∣+∣A3∩A1∣−∣A1∩A2∩A3∣=3n−3⋅2n+3×1−0=3n−3⋅2n+3.
Source: NuminaMath-1.5,
licensed Apache-2.0.
Statement and solution reproduced as published; topic, difficulty and ordering added
by this site.