4、 $\frac{1}{2}\left(8^{n}+10^{n}\right)-1$.
Let the number of "good numbers" of length $n$ be $a_{n}$, then $a_{1}=8$.
For $n \geqslant 2$, regarding $a_{n}$, on one hand, appending the digit 8 to the end of a "non-good number" of length $n-1$ turns it into a "good number" of length $n$, and there are $9 \times 10^{n-2}-a_{n-1}$ such "good numbers"; appending a non-8 digit to the end of a "good number" of length $n-1$ also turns it into a "good number" of length $n$, and there are $9 a_{n-1}$ such "good numbers". Clearly, these two types of "good numbers" of length $n$ are different (the last digit is different).
On the other hand, the reverse is also true. This establishes a one-to-one correspondence. Therefore,
$$
a_{n}=\left(9 \times 10^{n-2}-a_{n-1}\right)+9 a_{n-1}=8 a_{n-1}+9 \times 10^{n-2}(n \geqslant 2) \text {, }
$$

which means $\frac{a_{n}}{10^{n-2}}=8 \cdot \frac{a_{n-1}}{10^{n-2}}+9=\frac{4}{5} \times \frac{a_{n-1}}{10^{n-2}}+9$.
Let $b_{n}=\frac{a_{n}}{10^{n-2}}$, then
$$
b_{n}=\frac{4}{5} b_{n-1}+9(n \geqslant 2), b_{1}=10 a_{1}=80 \text {. }
$$

Let $b_{n}=c_{n}+t$ (where $t$ is a constant to be determined), then
$$
c_{n}+t=\frac{4}{5}\left(c_{n-1}+t\right)+9=\frac{4}{5} c_{n-1}+\left(\frac{4}{5} t+9\right) \text {. }
$$

Let $\frac{4}{5} t+9=t$, then $t=45$, thus,
$$
\begin{array}{l}
c_{n}=\frac{4}{5} c_{n-1}=\mathrm{L}=\left(\frac{4}{5}\right)^{n-1} c_{1}=\left(\frac{4}{5}\right)^{n-1}\left(b_{1}-45\right)=35\left(\frac{4}{5}\right)^{n-1} \\
b_{n}=35\left(\frac{4}{5}\right)^{n-1}+45 . \\
a_{n}=10^{n-2} b_{n}=10^{n-2}\left(35 \times \frac{4^{n-1}}{5^{n-1}}+45\right) \\
=7 \times 2^{3 n-4}+45 \times 10^{n-2}=\frac{7}{16} \times 8^{n}+\frac{9}{20} \times 10^{n}(n \geqslant 2) .
\end{array}
$$

Therefore, the total number of "good numbers" of length not exceeding $n$ is
$$
\begin{array}{l}
S_{n}=a_{1}+a_{2}+\mathrm{L}+a_{n}=\frac{7}{16} \sum_{k-1}^{n} 8^{k}+\frac{9}{20} \sum_{k-1}^{n} 10^{k} \\
=\frac{1}{2}\left(8^{n}+10^{n}\right)-1(n \geqslant 1)
\end{array}
$$
4. In a decimal positive integer, if it contains an even number (including zero) of the digit 8, it is called a "good number"; otherwise, it is called a "non-good number". Then, the number of all "good numbers" with length (number of digits) not exceeding $n$ ($n$ is a positive integer) is $\qquad$