31. 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{N}^{+}$. Let $S_{n}=\mathrm{C}_{n}^{1} f_{1}+\mathrm{C}_{n}^{2} f_{2}+\cdots+\mathrm{C}_{n}^{n} f_{n}$, find all positive integers $n$ such that $8 \mid S_{n}$.
31.
$$
\begin{array}{l} 
S_{n}=\sum_{k=1}^{n} \mathrm{C}_{n}^{k} f_{k}=\frac{1}{\sqrt{5}} \sum_{k=1}^{n} \mathrm{C}_{n}^{k}\left[\left(\frac{1+\sqrt{5}}{2}\right)^{k}-\left(\frac{1-\sqrt{5}}{2}\right)^{k}\right] \\
=\frac{1}{\sqrt{5}} \sum_{k=0}^{n} \mathrm{C}_{n}^{k}\left[\left(\frac{1+\sqrt{5}}{2}\right)^{k}-\left(\frac{1-\sqrt{5}}{2}\right)^{k}\right] \\
=\frac{1}{\sqrt{5}}\left[\left(1+\frac{1+\sqrt{5}}{2}\right)^{n}-\left(1+\frac{1-\sqrt{5}}{2}\right)^{n}\right] \\
=\frac{1}{\sqrt{5}}\left[\left(\frac{3+\sqrt{5}}{2}\right)^{n}-\left(\frac{3-\sqrt{5}}{2}\right)^{n}\right] \\
\quad \frac{3+\sqrt{5}}{2}+\frac{3-\sqrt{5}}{2}=3, \frac{3+\sqrt{5}}{2} \cdot \frac{3-\sqrt{5}}{2}=1,
\end{array}
$$
$\frac{3+\sqrt{5}}{2}, \frac{3-\sqrt{5}}{2}$ are the two roots of $\lambda^{2}-3 \lambda+1=0$.
$S_{n}$ satisfies the recurrence relation $S_{n}-3 S_{n-1}+S_{n-2}=0$,
From the expression of $S_{n}$, we know $S_{0}=0, S_{1}=1$, and by $S_{n}=3 S_{n-1}-S_{n-2}$ we get
$$
\begin{array}{l}
S_{2}=3 S_{1}-S_{0}=3, S_{3}=3 S_{2}-S_{1} \equiv 0(\bmod 8), \\
S_{4}=3 S_{3}-S_{2} \equiv 5(\bmod 8), S_{5}=3 S_{4}-S_{3} \equiv 7(\bmod 8), \\
S_{6}=3 S_{5}-S_{4} \equiv 0(\bmod 8), S_{7}=3 S_{6}-S_{5} \equiv 1(\bmod 8), \\
S_{8}=3 S_{7}-S_{6} \equiv 3(\bmod 8), \cdots \cdots
\end{array}
$$
The remainder of $S_{n}$ modulo 8 is a cyclic sequence $1 3 0 5 7 0 \longdiv { 3 0 5 7 0 } \ldots .$. Therefore, $8\left|S_{n} \Leftrightarrow 3\right| n$.