CombinatoricsDifficulty 6.5National OlympiadProve itHong Kong
Let k be a positive integer. Find the number of nonnegative integers n less than or equal to 10k satisfying the following conditions: (i) n is divisible by 3; (ii) Each decimal digit of n is one of the digits 2, 0, 1 or 7.
Solution
The answer is 34k−1 if 3∤k, and 34k+2 if 3∣k.
Note that n has exactly k digits, possibly starting with 0. We need to count the number N of integers of the form a1a2⋯ak such that each aj is one of 0, 1, 2, 7 and 3∣a1+a2+⋯+ak. Consider the generating function
Let cj be the coefficient of xj for each j. Then N=∑3∣jcj.
Let ω=2−1+23i be a cube root of unity. This means a number satisfying ω3=1 and ω=1. It has the property that ω2j+ωj+1=0 if 3∤j, and ω2j+ωj+1=3 if 3∣j. It follows that