5. Let $a_{n}=2^{n}, b_{n}=5 n-1\left(n \in \mathbf{Z}_{+}\right)$,
$$
S=\left\{a_{1}, a_{2}, \cdots, a_{2015}\right\} \cap\left\{b_{1}, b_{2}, \cdots, b_{a_{2015}}\right\} \text {. }
$$

Then the number of elements in the set $S$ is
5.504.

Since the set $\left\{b_{1}, b_{2}, \cdots, b_{2015}\right\}$ contains $2^{2015}$ elements, forming an arithmetic sequence with a common difference of 5, and each term has a remainder of 4 when divided by 5, we only need to consider the number of terms in the set $\left\{a_{1}, a_{2}, \cdots, a_{2015}\right\}$ that have a remainder of 4 when divided by 5.
For $k \in \mathbf{Z}_{+}$, we have
$$
\begin{array}{l} 
a_{4 k}=2^{4 k} \equiv 1(\bmod 5), \\
a_{4 k-1}=2^{4(k-1)} \times 2^{3} \equiv 2^{3} \equiv 3(\bmod 5), \\
a_{4 k-2}=2^{4(k-1)} \times 2^{2} \equiv 2^{2} \equiv 4(\bmod 5), \\
a_{4 k-3}=2^{4(k-1)} \times 2 \equiv 2(\bmod 5) . \\
\text { Let } 4 k-2 \leqslant 2015 \Rightarrow k \leqslant 504+\frac{1}{4}
\end{array}
$$

Therefore, the number of elements in set $S$ is 504.