4. (05 Shanghai) The general term formula of the sequence $\left\{f_{n}\right\}$ is $f_{n}=$
$$
\frac{1}{\sqrt{5}}\left[\left(\frac{1+\sqrt{5}}{2}\right)^{n}-\left(\frac{1-\sqrt{5}}{2}\right)^{n}\right], n \in \mathbf{Z}^{+} \text {, }
$$

Let $S_{n}=\mathrm{C}_{n}^{1} f_{1}+\mathrm{C}_{n}^{2} f_{2}+\mathrm{C}_{n}^{n} f_{n}$, find all positive integers $n$ such that $S_{n}$ is divisible by 8.
4. Solution: Let $\alpha=\frac{1+\sqrt{5}}{2}, \beta=\frac{1-\sqrt{5}}{2}$, then
$$
\begin{array}{l}
S_{n}=\frac{1}{\sqrt{5}} \sum_{i=1}^{n} \mathrm{C}_{n}^{i}\left(\alpha^{i}-\beta\right)=\frac{1}{\sqrt{5}} \sum_{i=0}^{n} \mathrm{C}_{n}^{i}\left(\alpha^{i}-\beta\right)= \\
\frac{1}{\sqrt{5}}\left(\sum_{i=0}^{n} \mathrm{C}_{n}^{i} \alpha^{i}-\sum_{i=0}^{n} \mathrm{C}_{n}^{i} \beta^{i}\right)=\frac{1}{\sqrt{5}}\left[(1+\alpha)^{n}-(1+\right. \\
\left.\beta)^{n}\right]=\frac{1}{\sqrt{5}}\left[\left(\frac{3+\sqrt{5}}{2}\right)^{n}-\left(\frac{3-\sqrt{5}}{2}\right)^{n}\right],
\end{array}
$$

Notice that $\frac{3+\sqrt{5}}{2}+\frac{3-\sqrt{5}}{2}=3, \frac{3+\sqrt{5}}{2} \cdot \frac{3-\sqrt{5}}{2}=$ 1, we can get $S_{n+2}=\frac{1}{\sqrt{5}}\left\{\left[\left(\frac{3+\sqrt{5}}{2}\right)^{n+1}-\left(\frac{3-\sqrt{5}}{2}\right)^{n+1}\right]\right.$
$$
\begin{array}{l}
\left.\left[\left(\frac{3+\sqrt{5}}{2}\right)+\left(\frac{3-\sqrt{5}}{2}\right)\right]-\left[\left(\frac{3+\sqrt{5}}{2}\right)^{n}-\left(\frac{3-\sqrt{5}}{2}\right)^{n}\right]\right\} \\
=3 S_{n+1}-S_{n} . \text { (*) }
\end{array}
$$

Therefore, the remainder of $S_{n+2}$ when divided by 8 is completely determined by the remainders of $S_{n+1}, S_{n}$ when divided by 8.
$\because S_{1}=\mathrm{C}_{1}^{1} f_{1}=1, S_{2}=\mathrm{C}_{2}^{1} f_{1}+\mathrm{C}_{2}^{2} f_{2}=3$, hence from (*) we can calculate that the remainders of $\left\{S_{n}\right\}$ when divided by 8 are $1,3,0,5,7,0,1,3, \cdots$, which is a sequence with a period of 6, thus $8\left|S_{n} \Leftrightarrow 3\right| n$.
Therefore, $8 \mid S_{n}$ if and only if $3 \mid n$.