<s>[INST] Puzzle: Cumulative Sum Divisible by 10 If we sum the first $4$ positive integers, we get $4 + 3 + 2 + 1 = 10$, which I think is pretty cool.
I'm interested in seeing solutions to the following puzzle:  If we take the cumulative sum of the first $N$ positive integers, how many times along the way will the sum be divisible by $10$?
In other words, define:
$$f(N) = \left|\left\{n \leq N \;:\; \sum_{i=1}^n i = \frac{n(n+1)}{2} \text{ is divisible by $10$}\right\} \right|$$
Is there a nice expression for $f(N)$?
 [/INST] 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}
</s>