4. A provincial TV station has $n$ ad insertion moments on a certain day, broadcasting a total of $m$ ads. The first time, one ad and $\frac{1}{8}$ of the remaining $(m-1)$ ads were broadcast, the second time, two ads and $\frac{1}{8}$ of the remaining ads were broadcast, and so on, following this pattern for ad insertion. In the last moment, the $n$-th time, the remaining $n$ ads were broadcast $(n>1)$. How many ad insertion moments were there that day? And find the number of ads $m$.

---

The translation maintains the original text's line breaks and format.
4. Let the number of ads left to be played after playing $k$ times be $a_{k}$, then the number of ads played at the $k$-th time is: $k+\frac{1}{8}\left(a_{k-1}-k\right)=$ $\frac{1}{8} a_{k-1}+\frac{7}{8} k$. Thus, $a_{k}=a_{k-1}-\left(\frac{1}{8} a_{k-1}+\frac{7}{8} k\right)=\frac{7}{8} a_{k-1}-\frac{7}{8} k$, hence $a_{k-1}=k+\frac{8}{7} a_{k}$.
From this recurrence relation, we get
$$
\begin{aligned}
m & =1+\frac{8}{7} a_{1}=1+\frac{8}{7}\left(2+\frac{8}{7} a_{2}\right)=1+2 \times \frac{8}{7}+\left(\frac{8}{7}\right)^{2} \cdot a_{2} \\
& =1+2 \times \frac{8}{7}+\left(\frac{8}{7}\right)^{2} \cdot\left(3+\frac{8}{7} a_{3}\right) \\
& =1+2 \times \frac{8}{7}+3 \times\left(\frac{8}{7}\right)^{2}+\left(\frac{8}{7}\right)^{3} \cdot a_{3} \\
& =\cdots \cdots \\
& =1+2 \times \frac{8}{7}+3 \times\left(\frac{8}{7}\right)^{2}+\cdots+n \times\left(\frac{8}{7}\right)^{n-1}+\left(\frac{8}{7}\right)^{n} \cdot a_{n} .
\end{aligned}
$$

By the definition of $a_{k}$, we know $a_{n}=0$.
Then $m=\sum_{l=1}^{n} l\left(\frac{8}{7}\right)^{t-1}$.
$$
\frac{8}{7} m=\sum_{t=1}^{n} l\left(\frac{8}{7}\right)^{l}
$$

By (2) - (1), we get $-\frac{m}{7}=1+\frac{8}{7}+\left(\frac{8}{7}\right)^{2}+\cdots+\left(\frac{8}{7}\right)^{n-1}-n \cdot\left(\frac{8}{7}\right)^{n}$
$$
=\frac{\left(\frac{8}{7}\right)^{n}-1}{\frac{8}{7}-1}-n \cdot\left(\frac{8}{7}\right)^{n}=7 \cdot\left(\frac{8}{7}\right)^{n}-7-n \cdot\left(\frac{8}{7}\right)^{n} \text {. }
$$

Thus, $m=49+(n-7) \cdot \frac{8^{n}}{7^{n-1}}$.
For $n>1$, it is clear that $|n-7|<7^{n-1}$. Also, $\left(8^{n}, 7^{n-1}\right)=1, m \in \mathbf{Z}$. Therefore, it must be that $n-7=0$. Hence, $n=7, m=49$.
Therefore, there are 7 ad broadcasting moments, and a total of 49 ads were played.