How to count numbers that contain specific digits What is the best way to count the numbers between $0$ and $N\in\mathbb{N}$ that contain  at least one occurrence (and possibly several occurrences) of specific digits (base $10$) in the set $\{d_1, d_2, ... d_n\}$ where $1\leq n \leq \lfloor \log_{10}(N) \rfloor + 1$?
For example, we are looking for the count of numbers between $1$ and $1000000$ that contain $3,5$ and $7$ at least once each. In this case, $357$ should be counted, as well as $753$, $735$, $357894$, but also $335577, 333571, \ldots$. The order in which $3,5$ and $7$ appear does not matter. On the other hand, $3, 37, 35, 35878, 73468 \ldots$ should not be counted, as they do not contain at least $1$ occurrence of each of $3$, $5$ and $7$.
 A: Don't consider them numbers, but 6 digit strings, including 0.
And w.l.o.g., consider the digits that should occur $A$, $B$, $C$, and they can be used arbitrarily.
Then I would use in/exclusion from https://en.wikipedia.org/wiki/Inclusion%E2%80%93exclusion_principle  to calculate the number.
The principle is more clearly seen in the case of three sets, which for the sets A, B and C is given by
$ |A\cup B\cup C|=|A|+|B|+|C|-|A\cap B|-|A\cap C|-|B\cap C|+|A\cap B\cap C|.$
Where:


*

*$|A| = |B| = |C| = 10^6-9^6$, cardinality of sequences contains at least one $A$ = everything except the sequences that do not contain $A$ (consist of the other $9$ symbols.)

*$|A \cup B | = |A \cup C | = |B \cup C | = 10^6-8^6 $ (used for 3.), cardinality of sequences containing at least one $A$ or $B$. 

*$|A \cap B | = |A \cap C | = |B \cap C | = |A|+|B|-|A\cup B| = 10^6 - 9^6 - 9^6 + 8^6$

*$|A \cup B \cup C | = 10^6-7^6 $
Be careful with all the signs, and you come up with something like: 
$$ 10^6-3 \cdot 9^6+3  \cdot 8^6-7^6 = 74460 $$
A: We are searching among the $10^6$ strings $000000$–$999999$.
We begin by setting up a list of the possible frequencies of the special digits $3$, $5$, $7$. These are three positive frequencies adding up to $\leq6$. A case search shows that there are the following $7$ types:
$$411,\quad 321,\quad 311,\quad 222,\quad 221,\quad 211,\quad 111\ .$$
We now determine for each type $ijk$ the number $N_{ijk}$ of possible strings of length $6$, whereby the nonused slots are filled with arbitrary digits from $0$, $1$,$2$,$4$,$6$,$8$,$9$.
For $411$ we can choose the special digit appearing four times in $3$ ways and place it four times in ${6\choose4}$ ways. The two remaining special digits can then be placed in $2$ ways. Hence $N_{411}=3\cdot{6\choose4}\cdot2=90$.
For $321$ we can choose the special digit appearing three times in $3$ ways and place it three times in ${6\choose3}$ ways. We then can choose the special digit appearing only once in $2$ ways and place it in $3$ ways. Hence $N_{321}=3\cdot{6\choose3}\cdot2\cdot3=360$.
Similarly $N_{311}=3\cdot{6\choose3}\cdot3\cdot2\cdot 7=2520$, whereby the factor $7$ comes from choosing the digit for the not yet used slot.
Etcetera.
