They say that when Carl Friedrich Gauss was eight, he discovered a secret for quickly adding all the numbers from 1 to 100.

Now, I’m going to teach you a trick I discovered, for adding up all the numbers from 1 to a number, where said number starts with 1, followed by one or more zeros.

So, for example, this cute trick only works for 10, or 1000, or 1000000000000, but not 13040.

Here’s how to do it.

- Start with the number that you want to add up to. We’ll call it N.
- Count the number of trailing zeros in it.
- Subtract one from that number.
- Let’s call that result K.
- Now, to start writing the answer, write down a 5.
- Write K zeros after it.
- Now, write down a 5.
- Now, write K zeros after it.
- You’re done!

Let’s do an example with 10000.

- Start with the number that you want to add up to. We’ll call it N. (N is 10000)
- Count the number of trailing zeros in it. (4)
- Subtract one from that number. (3)
- Let’s call that result K. (K = 3)
- Now, to start writing the answer, write down a 5. (5)
- Write K zeros after it. (5000)
- Now, write down a 5. (50005)
- Now, write K zeros after it. (50005000)
- You’re done! (Adding all the numbers from 1 to 10000 gives you 50005000.)

$$

\begin{aligned}

j \in \mathbb{N}: \sum_{n=1}^{10^{j}}n &= \frac{10^{j}(10^{j}+1)}{2} \\

&= \frac{10^{2j}+10^{j}}{2} \\[10pt]

&= 5 \times 10^{2j-1}+5 \times 10^{j-1} \\

\end{aligned}

$$