eolymp
bolt
Попробуйте наш новый интерфейс для отправки задач
Задачи

Сумма

опубликовано 24.03.2023, 12:58:38

I'll share my way of solving this problem.

Answer to the problem for 9, 99, 999, 9999 and so on has an easy recognizable pattern in the answer, it's easy to get, my calculation starts from those. After that I have to calculate numbers that has even or odd amount of digits. For odd: answer gets +5 every 10 numbers. For even: (it's the hard part) I imagine those numbers as a table, first column always subtract, I calculate all digits for the column and add them together considering their sign.

My solution is linear, takes up to 4ms (subtracting loading of java), probably even less.