how many 3-digit numbers can be formed using only the digits 1 to 7, if the number 2 must be included? (Repetitions are allowed)

The books says 127. Could someone please explain this? Thanks

3 answers

Since repetition is allowed, and the 2 must be included, it is easy to forget that the 2 can show up once, twice or even three times

case 1: only one 2
number of ways = 3(6)(6) = 108
(2XX, X2X, XX2, where X is one of the other 6 digits)

case 2: two 2's
number of ways = 3(6) = 18
(22X, 2X2, X22, where X is one of the other 6 digits)

case 3: three 2's , namely 222
number of ways = 1

total = 108+18+1 = 127
127=7^3-6^3

7^3 all 3-digit numbers, formed using
1,2,3,4,5,6,7
6^3 ... using 1,3,4,5,6,7
Mgraph
Very nice, good logic.