Puzzle: Cumulative Sum Divisible by 10

You need $20$ to divide $n(n+1)$. Note $n$ and $n+1$ are of opposite parity. Hence, $4$ divides either $n$ or $n+1$. $5$ divides either $n$ or $n+1$ since $5$ is a prime. Hence, we have $4$ cases which gives us as discussed below.

$1$. $4|n$ and $5|n$. This case is trivial. Since $(4,5)=1$, we get that $20|n$ and hence $n \equiv 0\bmod 20$.

$2$. $4|n$ and $5|(n+1)$. This means that $n = 4k_4$ and $n+1 = 5k_5$. Hence, we get that $5k_5 - 4k_4 = 1$.

Solving such general congruence fall under the Chinese remainder theorem, as TMM points out in the comments, and is certainly something which you should look at. In this case, we solve it as follows. Clearly, $(k_4,k_5) = (1,1)$ is a solution. In general, if $ax+by$ has integer solutions and $(x_0,y_0)$ is one such integer solution, then all integer solutions are given by $$(x,y) = \displaystyle \left( x_0 + k \frac{\text{lcm}[\lvert a \rvert,\lvert b \rvert]}{a}, y_0 - k \frac{\text{lcm}[\lvert a \rvert,\lvert b \rvert]}{b} \right)$$ where $k \in \mathbb{Z}$. Hence, we get that $(k_4,k_5) = (1+5k,1+4k)$. This gives us that $n = 20k+4$ i.e. $n \equiv 4 \bmod 20$.

$3$. $4|(n+1)$ and $5|n$. This means that $n = 5k_5$ and $n+1 = 4k_4$. Hence, we get that $4k_4 - 5k_4 = 1$. Clearly, $(k_4,k_5) = (4,3)$ is a solution. Hence, we get that $(k_4,k_5) = (4+5k,3+4k)$. This gives us that $n=20k+15$ i.e. $n \equiv 15 \bmod 20$.

$4$. $4|(n+1)$ and $5|(n+1)$. This case is again trivial. Since $(4,5) = 1$, we get that $20|(n+1)$ and hence $n \equiv 19 \bmod 20$.

To summarize, the solutions are given by

\begin{cases} n \equiv 0\bmod 20 &(\text{ if }4 \text{ divides }n \text{ and }5 \text{ divides }n)\\ n \equiv 4\bmod 20 & (\text{ if }4 \text{ divides }n \text{ and }5 \text{ divides }n+1)\\ n \equiv 15\bmod 20 & (\text{ if }4 \text{ divides }n+1 \text{ and }5 \text{ divides }n)\\ n \equiv 19\bmod 20 & (\text{ if }4 \text{ divides }n+1 \text{ and }5 \text{ divides }n+1) \end{cases}


Write $n$ in the form $20k+j$ where $0≤j<20$.

Then you have $n(n+1) = (20k+j)(20k+j+1) = 400k^2 + 40kj + 20k + j^2 + j$ which is obviously a multiple of 20 if and only if $j^2+j$ is. So the problem has been reduced to finding $0≤j<20$ where $j(j+1)$ is a multiple of 20; this occurs for $j=0,4,15,19$, so the solutions all have the form $n=20k+\{0,4,15,19\}$ for some integer $k$.


Where did I get the inspiration to write $n$ in the form $20k+j$? I guessed that it would repeat with period 10 or 20, and I looked at the list of triangular numbers in OEIS and saw that multiples of 10 did indeed appear at $n=4,15,19,20,24$, so 20 seemed to be the way to go.

Why did I guess that it would repeat with period 10 or 20? The main reason is that questions about when an polynomial $P(n)$ is divisible by $q$ usually does something like that, because if you calculate $P(n+q) - P(n)$ the constant term cancels, as do all the terms that are pure in $n$, and leaves you with some higher-order terms that are all divisible by $q$.

I knew that was the thing to try because I have seen a lot of problems of that type.

Addendum: How many solutions lie between 1 and $N$? Write $N=20k+j$ as before, and the answer is $4k$ plus a fudge factor. The fudge factor is 0 if $j<4$, 1 if $4≤j<15$, 2 if $15≤j<19$, and 3 if $j=19$.