Practice on Toph

Participate in exhilarating programming contests, solve unique algorithm and data structure challenges and be a part of an awesome community.

Playing With Numbers

By saif_sust · Limits 1s, 512 MB

Mama and Mami are the ultimate best friends and they love 10-Base Numbers more than anything. Since anyone can make a 10-Base Number using digits from 0 to 9. For example 1, 2, 1012, 905, 100215 and 1234567890 are some 10-Base Numbers.

This morning Mama asked Mami, how many digits are there from A to B inclusive? And Mami also asked Mama a similar question, what is the sum of the digits from A to B inclusive? However, both Mama and Mami don’t have any clue. So they are asking your help to find the answers since you are the best programmer in their neighborhood.


Input starts with an integer T (≤ 10000), denoting the number of test cases.
Each case contains two integers A and B, (1 ≤ A, B ≤ 1018)


For each case, print the number of digits and sum of digits from A to B inclusive. Both results can be large. So, print the results modulo 1000000007.


1 10
100 115
3457858 9584524158565
11 46
48 82
678991943 415085735



53% Solution Ratio

NirjhorEarliest, Nov '17

dip_BRURFastest, 15966.8s

fsshakkhorLightest, 262 kB

NirjhorShortest, 735B


Login to submit


Contact with M. Tahmid Hossain Olee.

Toph uses cookies. By continuing you agree to our Cookie Policy.