Example 3 Let $S$ be a subset of $\{1,2,3, \cdots, 50\}$ with the following property: the sum of any two distinct elements of $S$ is not divisible by 7. Then, the maximum number of elements in $S$ is ( ).
(A) 6
(B) 7
(C) 14
(D) 22
(E) 23
(43rd American High School Mathematics Examination)
Solution: Divide $A=\{1,2,3, \cdots, 50\}$ into 7 subsets: $A_{0}, A_{1}, A_{2}, A_{3}, A_{4}, A_{5}, A_{6}$, where the elements of $A_{i}$ have a remainder of $i$ when divided by 7 ($i=0,1,2,3,4,5,6$), i.e., $A_{0}=\{0,7,14,21,28,35,42,49\}$,
$$
\begin{array}{l}
A_{1}=\{1,8,15,22,29,36,43,50\}, \\
A_{2}=\{2,9,16,23,30,37,44\}, \\
A_{3}=\{3,10,17,24,31,38,45\}, \\
A_{4}=\{4,11,18,25,32,39,46\}, \\
A_{5}=\{5,12,19,26,33,40,47\}, \\
A_{6}=\{6,13,20,27,34,41,48\},
\end{array}
$$
$S$ can contain at most one element from $A_{0}$. However, if $S$ contains some elements from any other subset, then it can contain all elements of that subset. Since $A_{1}$ contains 8 elements, and each of the other subsets contains 7 elements. Moreover, $S$ cannot contain elements from both $A_{1}$ and $A_{6}$, or from both $A_{2}$ and $A_{5}$. Therefore, $1+8+7+7=23$ elements, hence the answer is (E).