Editor

Digit Sums Over a Range

#443 · Math · Expert · 220 XP · about 40 min

The digit sum of a number adds up its decimal digits: the digit sum of 2026 is 2 + 0 + 2 + 6 = 10.

Write digit_sum_total(lo, hi) that returns the total of the digit sums of every whole number from lo to hi, both included.

Examples

digit_sum_total(1, 10)     # returns 46
digit_sum_total(10, 12)    # returns 6
digit_sum_total(5, 5)      # returns 5

From 10 to 12 the digit sums are 1, 2 and 3, which make 6.

Constraints

  • 0 <= lo <= hi <= 10^18
  • The answer can be bigger than 10^19; return it as an exact integer.

Fastest solvers

Leaderboard

First solves only, ranked by stars and then time.