4. Person A and Person B are stacking pyramids with some spheres of radius 2. Person A stacks a square pyramid: composed of $n$ layers, with 1 sphere on the top layer, 4 spheres on the second layer, 9 spheres on the third layer, ... each sphere touching four spheres in the layer below. Person B stacks a triangular pyramid: composed of $n$ layers, with 1 sphere on the top layer, 3 spheres on the second layer, 6 spheres on the third layer, ... each sphere touching three spheres in the layer below. If Person A uses 2109 spheres, then Person B needs to use at least $\qquad$ spheres to ensure that his pyramid is taller than Person A's.
4. 816 .

Notice that, $1^{2}+2^{2}+\cdots+18^{2}=2109$.
Thus, Pyramid A has 18 layers.
According to the formula for calculating the height of a square pyramid, Pyramid A's height is $34 \sqrt{2}+4$.
Let Pyramid B have $n$ layers. Then
$$
\begin{array}{l}
4+(n-1) \frac{2 \sqrt{6}}{3} \geqslant 4+34 \sqrt{2} \\
\Rightarrow n \geqslant 16 .
\end{array}
$$

Therefore, the required sum is $\sum_{i=1}^{16} \frac{i(i+1)}{2}=816$.