2. From the numbers $1,2, \cdots, 2017$, select $n$ numbers such that the difference between any two of these $n$ numbers is a composite number. The maximum value of $n$ is $\qquad$
2. 505 .

Notice that 4 is the smallest composite number.
Taking all numbers of the form $4k+1$, it is clear that the difference between any two such numbers is a multiple of 4, and thus composite. This is the best possible scenario, because in any sequence of eight consecutive numbers $m, m+1, \cdots, m+7$, the differences between any two numbers are $1, 2, \cdots, 7$. The differences between the chosen numbers can only be the composite numbers 4 or 6, so at most only two numbers can be chosen from any sequence of eight consecutive numbers.
$$
\begin{array}{l}
\text { Also, } 1 \leqslant 4k+1 \leqslant 2017 \Rightarrow 0 \leqslant k \leqslant 504 \text {, then } \\
n_{\text {max }}=505 .
\end{array}
$$