<s>[INST] How many numbers are there which only contain digits $4$ and $7$ in them? I wanna know how many numbers $n$ are there which only contain digits $4$ and $7$ in them, where $1 ≤ n ≤ 10^9$.
Ex: $4, 7, 44, 47, 74, 77, ...$
I am trying to find a general equation to compute the numbers, given how many digits, which is $2$ in this case, and the range, which is $1 ≤ n ≤ 10^9$ in this case.
 [/INST] There are $2$ with length $1$, $2^2$ with length $2$, $2^3$ with length $3$, et cetera.
That observation leads to a total of:$$2+2^2+2^3+\cdots+2^9=2^{10}-2$$
The last equation on base of: $$(2-1)(2+2^2+2^3+\cdots+2^9)=(2^2+2^3+\cdots+2^{10})-(2+2^2+2^3+\cdots+2^9)=2^{10}-2$$
</s>