Example 8 Given the sequence $\left\{a_{n}\right\}$ with terms
$$
1,1,1,2,3,3,3,4,5,5,5,6,7,7,7,8, \cdots \text {. }
$$

Find $a_{n}$ and $S_{n}$.
Solution: The general term of the sequence $1,1,1,1,2,2,2,2,3,3,3,3,4,4$,
$4,4, \cdots$ is $\left[\frac{n+3}{4}\right]$.
The general term of the sequence $0,0,0,1,1,1,1,2,2,2,2,3,3,3$, $3,4, \cdots$ is $\left[\frac{n}{4}\right]$.

Adding the corresponding terms, we get the sequence $1,1,1,2,3,3,3,4$, $5,5,5,6,7,7,7,8, \cdots$ with the general term
$$
\left[\frac{n+3}{4}\right]+\left[\frac{n}{4}\right]
$$

Thus, $a_{n}=\left[\frac{n+3}{4}\right]+\left[\frac{n}{4}\right]$.
To find the sum of the first $n$ terms, this problem can be viewed as:
Let the first four terms of the sequence $\left\{a_{n}\right\}$ be $1,1,1,2$, and $a_{n+4}$ $=a_{n}+2(n=1,2, \cdots)$. Find $S_{n}$.
Therefore, we have the following solution:
Let the undetermined constants $i, m \in \mathbf{N}, k$ be non-negative integers, $i \in$ $\{1,2,3,4\}, m$ be the segment order number, such that $n=4 m+i$. Then
$$
\begin{array}{l} 
S_{n}=5+13+21+\cdots+(8 m-3) \\
\quad+(2 m+1) i+k \\
= m(4 m+1)+(2 m+1) i+k \\
= \frac{n-i}{4}\left(4 \cdot \frac{n-i}{4}+1\right)+\left(2 \cdot \frac{n-i}{4}+1\right) i+k \\
= \frac{n^{2}+n-i^{2}+3 i+4 k}{4} \\
= \frac{n^{2}+n+2}{4}-\frac{i^{2}-3 i-4 k+2}{4} . \\
\because 0 \leqslant \frac{i^{2}-3 i+2-4 k}{4}<1(i=1,2,3,4, k \\
=0,0,0,1)
\end{array}
$$
(Continued on page 40)