Denote the sum of the digits of n is s(n)
s(49) = 13
s(94) = 13
but 49+1 = 50 , which s(50) = 5 , and 94+1 = 95 , which s(95) = 14 . Therefore, if you were only given that the sum of the digits n is 13, you have at least two different possible answers for the sum of the digits n+1 . Need more information about n.
I really think the key knows that if n ends with 9, s(n+1) will be at most s (n) - 9. (Ah, where the ypercube answer is.) So, if you have xxxx9 (where the last x is nothing but 9), s(xxxx9 + 1) = s(xxxx9) - 9 + 1 . If you have xxx99, s(xxx99 + 1) = s(xxx99) - 18 + 1 , etc.
So, what can speed it up if you count all 10, 100, thousands, etc. in its range.
(Again, I see that ypercube beat me before the hit). It seems that the formula for A037123 does just that (but from 0 to n). (Lets call it a(n) )
So, finally, since you want to get the sum of the sum of the digits from n to n + r, and not the sum from 1 to n, we need to see if we can get the formula for the sum of the sum of the digits for the range ss(n,n+r)
It will be easy
ss(n,n+r) = a(n+r) - a(n-1)
source share