How many k-digit numbers are both divisible by 3 and include the digit 3? At first I thought I could simply count how many (k-1)-digit numbers are divisible by 3 and multiply by k, accounting for the different possible placements of the final 3. But It seems that method includes duplicates. 
Any direction, such as Inclusion-Exclusion or something cleverer would be appreciated. I'd like to be able to apply it to 9 instead of 3 as well. (A general method for any digit d would actually solve the original problem eliciting this question.)

We get from first principles the generating function
$$f(z) = (z+z^2+A+z+z^2+1+z+z^2+1) \\ \times
\prod_{q=1}^{k-1} (1+z+z^2+A+z+z^2+1+z+z^2+1).$$
This is 
$$f(z) = (A + 2 + 3z + 3z^2)
\prod_{q=1}^{k-1} (A + 3 + 3z + 3z^2).$$ 
We obtain for the desired count
$$\frac{1}{3} 
\sum_{q=0}^2
\left. \left(f(z) - \left. f(z)\right|_{A=0}\right)
\right|_{A=1, z=\exp(2\pi i q/3)}.$$
Here we  subtract the values  for $A=0$ to remove  contributions where
the digit three does not occur.
The value for $q=0$ is
$$(A + 8)
\prod_{q=1}^{k-1} (A + 9).$$ 
Subtracting the value for $A=0$ and setting $A=1$ yields
$$9\times 10^{k-1} - 8 \times 9^{k-1}.$$ 
For $q=1$ and $q=2$ we get
$$(A -  1) \prod_{q=1}^{k-1} A.$$ This  is zero when we  set $A=0$ and
also when $A=1$ and hence makes no contribution.
This yields for the end result
$$\frac{1}{3} (9\times 10^{k-1} - 8 \times 9^{k-1})
= 3\times 10^{k-1} - 24 \times 9^{k-2}.$$ 
