$ 1+ \sum_{i=1}^n \lfloor \log_{10} i + 1 \rfloor $ where the $1$ infront is to account for the number $0$.
If you are looking for a compact form - that relieves you of summing the terms individually - you can aggregate terms:
- if $n<10$ then result $= n+1$
- if $10\le n < 100$ then result $= 10+2\cdot (n-9)$
- if $100\le n < 1000$ then result $= 190 + 3\cdot (n-90)$
- if $1000\le n < 10000$ then result $= 190 + 3*900 + 4\cdot (n-900) = 2890 + 4\cdot (n-900)$ and so on
In general: if $n$ has $m=\lfloor \log_{10} n +1 \rfloor$ digits, then the result is $ 10\cdot 1 + 90\cdot 2 + 900\cdot 3 + \dots + 9\cdot 10^{m-2}\cdot (m-1) + m\cdot (n-9\cdot 10^{m-2})$