Digit Sum of a Range
InterviewTime limit1sMemory limit128 MB
For each query [a,b] with b up to 10^15, output the sum of all decimal digits of every integer in the range.
- Level
Medium6 of 10
- Topics
- Math, Dynamic programming, Implementation, Prefix sum
- Solved
- No attempts yet
Problem
The digit sum of a range is the sum of every digit of every integer contained in that range. For example, the digit sum of the range is:
Given two integers and , write a program that computes the digit sum of the range .
Input
The first line contains the number of test cases . ()
Each of the next lines contains one test case: two integers and separated by a space. ()
Output
For each test case, print the digit sum of the range on its own line.