# Problem of the Week Problem E and Solution It’s the Ones that We Want

## Problem

The sum of the first $$n$$ positive integers is $$1+2+3 + \cdots + n$$.
We define $$a_n$$ to be the ones digit of the sum of the first $$n$$ positive integers.

For example,

\begin{aligned} 1=1 \ \ &\text{and} \ \ a_1 = 1,\\ 1+2=3 \ \ &\text{and} \ \ a_2 = 3,\\ 1 + 2 + 3 = 6 \ \ &\text{and}\ \ a_3 = 6,\\ 1 + 2 + 3 + 4 = 10 \ \ &\text{and}\ \ a_4 = 0,\\ 1 + 2 + 3 + 4 + 5 = 15 \ \ &\text{and}\ \ a_5 = 5. \end{aligned} Thus, $$a_1 + a_2 + a_3 + a_4 + a_5 = 1 + 3 + 6 + 0 + 5 = 15$$.

Determine the smallest value of $$n$$ such that $$a_1 + a_2 + a_3 + \cdots + a_n \geq 2024$$.

## Solution

Let’s start by examining the values of $$a_n$$ until we start to see a pattern.

We know $$a_1=1$$, $$a_2=3$$, $$a_3 = 6$$, $$a_4 = 0$$, and $$a_5=5$$.

Unfortunately, we do not have a pattern yet. We need to keep calculating values of $$a_n$$. Since $$15 + 6 = 21$$, $$a_6 = 1$$.

Notice that we can determine the ones digit of the sum of the first $$n$$ integers from the ones digit from the sum of the first $$n-1$$ integers and the ones digit of $$n$$. For example, to calculate $$a_7$$, we simply need to know that $$a_6 = 1$$ and the sum $$1+7 = 8$$ has ones digit $$8$$. So $$a_7=8$$. Thus, continuing on, we know

• $$a_8 = 6$$, since $$a_7+8 = 16$$

• $$a_9 = 5$$, since $$a_8+9 = 15$$

• $$a_{10} = 5$$, since $$a_9 + 0 = 5$$

• $$a_{11} = 6$$, since $$a_{10} + 1 = 6$$

• $$a_{12} = 8$$, since $$a_{11} + 2 = 8$$

• $$a_{13} = 1$$, since $$a_{12} + 3 = 11$$

• $$a_{14} = 5$$, since $$a_{13} + 4 = 5$$

• $$a_{15} = 0$$, since $$a_{14} + 5 = 10$$

• $$a_{16} = 6$$, since $$a_{15} + 6 = 6$$

• $$a_{17} = 3$$, since $$a_{16} + 7 = 13$$

• $$a_{18} = 1$$, since $$a_{17} + 8 = 11$$

• $$a_{19} = 0$$, since $$a_{18} + 9 = 10$$

• $$a_{20} = 0$$, since $$a_{19} + 0 = 0$$

• $$a_{21} = 1$$, since $$a_{20} + 1 = 1$$

The values of $$a_n$$ should repeat now. Can you see why?
Since $$a_{21} = a_1$$ and the ones digit of $$22$$ equals the ones digit of $$2$$, $$a_{22} = a_2$$.
Similarly, since $$a_{22} = a_2$$ and the ones digit of $$23$$ equals the ones digit of 3, $$a_{23} = a_3$$.
We will also have $$a_{24} = a_4$$, and so on.

Therefore, the values of $$a_n$$ will repeat every $$20$$ values of $$n$$.

We can calculate \begin{aligned} & a_1 + a_2 + a_3 + a_4 + a_5 + a_6 + a_7 + a_8 + a_9 + a_{10} \\ & ~~~+ a_{11} + a_{12} + a_{13} + a_{14} + a_{15} + a_{16} + a_{17} + a_{18} + a_{19} + a_{20}\\ = & ~ 1 + 3 + 6 + 0 + 5 + 1 + 8 + 6 + 5 + 5 \\ & ~~~+ 6 + 8 + 1 + 5 + 0 + 6+ 3 + 1 + 0 + 0 \\ = & ~ 70 \end{aligned} Since the values of $$a_n$$ repeat every $$20$$ values of $$n$$, it is also true that $$a_{21} + a_{22} + a_{23} + \cdots + a_{39} + a_{40} = 70$$, and $$a_{41} + a_{42} + a_{43} + \cdots + a_{59} + a_{60} = 70$$, and so on.

Since $$\dfrac{2024}{70} = 28\dfrac{32}{35}$$, there are $$28$$ complete cycles of the $$20$$ repeating values of $$a_n$$.

Therefore, the sum of the first $$28\times 20 = 560$$ values of $$a_n$$ sum to $$28\times 70 = 1960$$.

In other words, $$a_1 + a_2 + a_3 +\cdots + a_{559} + a_{560} = 1960$$.

Let’s keep adding values of $$a_n$$ until we reach 2024. \begin{aligned} a_{561} + a_{562} &+ a_{563} + a_{564} + a_{565} + a_{566} + a_{567} + a_{568} + a_{569} + a_{570}\\ &= a_{1} + a_{2} + a_{3} + a_{4} + a_{5} + a_{6} + a_{7} + a_{8} + a_{9} + a_{10}\\ & = 1 + 3 + 6 + 0 + 5 + 1 + 8 + 6 + 5 + 5\\ & = 40 \end{aligned}

Therefore, $$a_1 + a_2 + a_3 +\cdots +a_{569} + a_{570} = 1960 + 40 = 2000$$.

We also know that $$a_{571} = a_{11} = 6$$ , $$a_{572} = a_{12} = 8$$, $$a_{573} = a_{13} = 1$$ , $$a_{574} = a_{14} = 5$$, and $$a_{575} = a_{15} = 0$$.

Thus, \begin{aligned} a_1 + a_2 + a_3+ \cdots +a_{569} + a_{570} + a_{571}+ a_{572} + a_{573} + a_{574} + a_{575} &= 2000 + 6 + 8 + 1 + 5 + 0\\ &= 2020 \leq 2024 \end{aligned} and \begin{aligned} a_1 + a_2 + a_3+ \cdots +a_{569} + a_{570} + a_{571}+ a_{572} + a_{573} + a_{574} + a_{575} + a_{576} &= 2020 + 6 \\ &= 2026 \geq 2024 \end{aligned}

Therefore, the smallest value of $$n$$ such that $$a_1 + a_2 + a_3 + \cdots + a_n \geq 2024$$ is $$n = 576$$.