24. Find the sum of all positive integers $n, 1 \leq n \leq 5000$, for which
$$
n^{2}+2475 n+2454+(-1)^{n}
$$
is divisible by 2477 . (Note that 2477 is a prime number.)
24. 9912
The problem is equivalent to finding all values of $n$ that satisfies the following congruence:
$$
n^{2}-2 n-23+(-1)^{n} \equiv 0(\bmod 2477) \text {. }
$$

If $n$ is odd, then $(-1)^{n}=-1$. Then, we have:
$$
\begin{array}{c}
n^{2}-2 n-24 \equiv 0(\bmod 2477) \\
(n-6)(n+4) \equiv 0(\bmod 2477) .
\end{array}
$$

This gives us solutions $n \equiv 6$ and $n \equiv-4$ (modulo 2477). Since 2477 is prime, these are the only roots modulo 2477 . This yields the solutions $6,2483,2473$ and 4950 . We only accept the odd values, 2483 and 2473 .
If $n$ is even, then $(-1)^{n}=1$. Then, we have
$$
n 2-2 n-22 \equiv 0(\bmod 2477) \text {. }
$$

This gives $n \equiv 1 \pm \sqrt{23}(\bmod 2477)$. Again, because 2477 is prime, these two are the only roots, modulo 2477 . Since $2477+23=2500=50^{2}$, note that $\sqrt{23} \equiv 50(\bmod 2477)$, which then gives the solutions $n \equiv 51$ and $n \equiv-49$ (modulo 2477), yielding us the solutions 51, 2528, 2428 and 4905. We only accept the even values, 2528 and 2428 .

Thus, the sum of all the solutions is $2483+2473+2528+2428=9912$.