Example 1 Calculate the sum $S=\sum_{n=1}^{509}\left[\frac{511 n}{509}\right]$.
Analysis First, $\frac{511}{509}$ should be converted to a mixed number form, so that $\frac{511 n}{509}$ can be expressed as the sum of an integer and another part.
Solution $S=\sum_{n=1}^{509}\left[n+\frac{2 n}{509}\right]=\sum_{n=1}^{509}\left(n+\left[\frac{2 n}{509}\right]\right)=\sum_{n=1}^{509} n+\sum_{n=1}^{509}\left[\frac{2 n}{509}\right]$.
When $1 \leqslant n \leqslant 254$, $2 n<509,\left[\frac{2 n}{509}\right]=0$;
When $255 \leqslant n \leqslant 508$, $509<2 n<509 \times 2,\left[\frac{2 n}{509}\right]=1$;
When $n=509$, $\left[\frac{2 n}{509}\right]=2$.
Therefore, $\sum_{n=1}^{509}\left[\frac{2 n}{509}\right]=\sum_{n=1}^{254}\left[\frac{2 n}{509}\right]+\sum_{n=255}^{508}\left[\frac{2 n}{509}\right]+\left[\frac{2 \times 509}{509}\right]$
$=0 \times 254+1 \times 254+2=256$.
And $\sum_{n=1}^{509} n=\frac{1}{2} \cdot 509 \cdot 510=129795$.
Thus, $S=129795+256=130051$.