### Omar_Hafez's blog

By Omar_Hafez, history, 6 weeks ago,

Hello codeforces, I solved This problem from atcoder with the "Obvious" brute-force solution which is O(N). But when I take a look at the editorial I found a Beautiful mathematical solution that solves it in O(1) O(N) but with a lower constant factor, use lower memory and easy beautiful code. But unfortunately, I didn't understand it so Can anyone please explain it to me?

 » 6 weeks ago, # | ← Rev. 2 →   0 I will just try to explain where the 9 comes from, without getting to the full solution. Let y = x + x/10 + x/100 + x/1000 Note there are only these 4 terms. Then, y = (1000x + 100x + 10x + x) / 1000 y = 1111x/1000 y = 9999x/9000 y = (10000x-x) / 9000 y = 10x/9 - x/9000