Solution:
We shall say that the order of Spas is 1, the order of his parents is 2, the order of their parents is 3, etc. Write the number of the heads of any dragon in ternary base: Spas has 1 head, his mother 10 heads, his father 11 heads, etc. It follows by induction on the order of the dragons that the heads of the dragons of order n are n-digit numbers whose ternary representation contains no digit 2.
It follows that if two dragons have a+b=k (a>b) heads in total and k is written in ternary base, then a and b have 0 at the positions where k has 0 and 1 at the positions where k has 2. Moreover, if k has 1 at some position, then one of a and b has 1 and the other one has 0 at the same position.
So if the ternary representation of k contains no 1, then a=b and hence k is not a good number. If this representation contains at least two 1's (k=…1…1…), we have two possibilities: (a=…1…1…,b=…0…0…) and (a=…1…0…,b=…0…1…). Such a k is not a good number except for the case when k contains exactly two 1's and the other digits are 0.
If k contains exactly one 1, then a has 1 and b has 0 at this position and the other digits of a and b are uniquely determined. The only exception is the case when the remaining digits of k are 0. All the numbers with one 1 and at least one 2 are good.
Since 2003=22020123, the number 2003 is good.
Let us count all good numbers with at most 7 digits. One has (27)=21 numbers with exactly two 1's and 0 at the other positions. There are 26−1=63 non-zero numbers with at most 6 digits equal to 0 or 2. There exist 7 possibilities to put 1 in such numbers. So we get 7⋅63=441 numbers and adding the above 21 numbers, we obtain 462 good numbers with at most 7 digits.
We shall count the 7-digit good numbers greater than 22020123. They are 22020213,22021003,22021023,22021203,22021223,22022013,22022103, 22022123,22022213, 16 numbers of the form 221mnpq3, where m,n,p,q∈{0;2} and 4⋅8=32 numbers of the form 222mnpq3, where exactly one of the digits m,n,p,q is equal to 1. Thus, there are 1+9+16+32=58 7-digit good numbers greater than 22020123.
Hence we have 462−58=404 good numbers smaller than 2003.