Example 42 (1991 National High School League Question) Let $S=\{1,2, \cdots, n\}, A$ be an arithmetic sequence with at least two terms and a positive common difference, all of whose terms are in $S$, and adding any element from $S$ to $A$ cannot form an arithmetic sequence with the same common difference as $A$. Find the number of such $A$s, where sequences with only two terms are also considered arithmetic sequences.

---

Here is the translation, preserving the original text's line breaks and format.
Solution 1: Let the first term of $A$ be $a$, and the common difference be $d$. According to the problem, $a-d \leqslant 0, a+d \leqslant n$, which means $a \leqslant d \leqslant n-a$, thus $a \leqslant \frac{n}{2}$.

For each $a$, the common difference can take $n-2a+1$ values, meaning there are $n-2a+1$ arithmetic sequences with $a$ as the first term. Therefore, the number of the required arithmetic sequences is
\[
\begin{aligned}
\sum_{u=1}^{\left[\frac{n}{2}\right]}(n-2a+1) & = n\left[\frac{n}{2}\right] - \left[\frac{n}{2}\right]\left(\left[\frac{n}{2}\right]+1\right) + \left[\frac{n}{2}\right] = \left(n - \left[\frac{n}{2}\right]\right)\left[\frac{n}{2}\right] \\
& = \left\{\begin{array}{l}
\frac{n^{2}}{4} \text{ ( } n \text{ is even) }, \\
\frac{n^{2}-1}{4} \text{ ( } n \text{ is odd). }
\end{array}\right.
\end{aligned}
\]

Solution 2: When $n=2k$, any arithmetic sequence $A$ that meets the conditions must have two adjacent terms such that the first term is in $\{1, 2, \cdots, k\}$ and the second term is in $\{k+1, k+2, \cdots, 2k\}$. By choosing one number from $\{1, 2, \cdots, k\}$ and one number from $\{k+1, k+2, \cdots, 2k\}$, a unique arithmetic sequence $A$ that meets the conditions can be formed. This correspondence is one-to-one, so the number of such $A$ is $C_{k}^{1} \cdot C_{k}^{1} = k^{2} = \frac{\dot{n}^{2}}{4}$.

When $n=2k+1$, the situation is similar, with the only difference being that the second set $\{k+1, k+2, \cdots, 2k+1\}$ has $k+1$ elements. In this case, the number of such $A$ is $C_{k}^{1} C_{k+1}^{1} = k(k+1) = \frac{n^{2}-1}{4}$.