Calculate number of elements in a set
The cardinality of the second set can be calculated as the complement of those numbers not containing $3$, thus (since we can choose each digit independently for $10^3=1000$ possibilities) $10^3-9^3=271$.
Those numbers in the intersection of the two sets, those divisible by $3$ and containing it as a digit, may be calculated as the sum of the following disjoint cases:
- One $3$. The $3$ may be placed in any one of $3$ positions, and the other two digits must form a number divisible by $3$. There are $33$ such two-digit numbers, but we exclude $03,30,33,36,39,63,93$ for including a $3$ themselves. Hence there are $3×(33-7)=78$ numbers in this case.
- Two $3$s. Again, the $3$'s may be placed in $3$ configurations. The remaining digit must be $0,6,9$, so there are $3×3=9$ numbers in this case.
- The only admissible number with three threes is of course $333$.
Thus the intersection contains $78+9+1=88$ numbers. The desired answer is then $333+271-88=516$.