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.)
 A: Use inclusion/exclusion principle:

Include the number of positive values with $k$ digits:
$$\color\red{9\cdot10^{k-1}}$$

Exclude the number of positive values with $k$ non-$3$ digits:
$$\color\green{8\cdot9^{k-1}}$$

Exclude the number of positive values with $k$ digits that are not divisible by $3$:
$$\color\orange{9\cdot10^{k-1}-9\cdot10^{k-1}/3}$$

Include the number of positive values with $k$ non-$3$ digits that are not divisible by $3$:
$$\color\purple{8\cdot9^{k-1}-8\cdot9^{k-1}/3}$$

Finally, we get:
$$\color\red{9\cdot10^{k-1}}-\color\green{8\cdot9^{k-1}}-(\color\orange{9\cdot10^{k-1}-9\cdot10^{k-1}/3})+(\color\purple{8\cdot9^{k-1}-8\cdot9^{k-1}/3})$$

Which can be reduced to:
$$3\cdot10^{k-1}-24\cdot9^{k-2}$$
A: We count the number of sequences of $k$ digits that do not start with $0$, do not contain $3$ and have sum of digits multiple of $3$.
How many are there?
There are $8\times 9^{k-2}\times 3$ such sequences, this is because there are $8\times 9^{k-2}$ options for the first $k-1$ terms, and then, the last term will have its congruence class pre-determined by the other options, and each congruence class has $3$ options (if we exclude $3$).
However, you want the number of sequences that do contain $3$. How many sequences are there in total? That is, sequences of length $k$ that don't start with $0$ and have sum of digits divisible by $3$? This is equal to the number of multiples of $3$ between $10^{k-1}$ and $10^{k}-1$ inclusive, which is $3\times 10^{k-1}$.
So your final result is $3\times10^{k-1}-8\times9^{k-2}\times 3$
A: 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}.$$ 
