2. $36 S$ is a subset of $\{1,2, \cdots, 1989\}$, and the difference between any two numbers in $S$ cannot be 4 or 7. How many elements can $S$ have at most?
[Solution] First, we prove: In any 11 consecutive integers in the set $\{1,2, \cdots, 1989\}$, at most 5 can be elements of $S$.

In fact, let $T=\{1,2, \cdots, 11\}$. We examine the subsets $\{1,5\},\{2,9\}$, $\{3,7\},\{4,11\},\{6,10\},\{8\}$ of $T$. Clearly, each of these subsets can have at most one element in $S$.
If $T$ has 6 elements in $S$, then
$$
8 \in S \Rightarrow 1 \notin S \Rightarrow 5 \in S \Rightarrow 9 \notin S \Rightarrow 2 \in S \Rightarrow 6 \notin S \Rightarrow 10 \in S \Rightarrow 3
$$
$\notin S \Rightarrow 7 \in S \Rightarrow 11 \notin S \Rightarrow 4 \in S \Rightarrow 8 \notin S$.
This leads to a contradiction.
Therefore, $T$ can have at most 5 elements in $S$.
A subset of $T$ with 5 elements is possible, for example:
$$
T^{\prime}=\{1,3,4,6,9\},
$$

Let $A=\{k+1, k+2, \cdots, k+11\}$ be a subset of $\{1,2, \cdots, 1989\}$. Then, by analogy with the above proof, $A$ can have at most 5 elements in $S$.
Since $S^{\prime}=\left\{k+11 n \mid k \in T^{\prime}, n \in I, k+11 n \leqslant 1989.\right\}$
and $1989=180 \times 11+9$.
Therefore, $S$ can have at most $181 \times 5=905$ elements.