How many k-digit numbers are both divisible by 3 and include the digit 3?

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}$$


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$