Distance Between Two Integers
Time limit3sMemory limit128 MB
Sum the digitwise absolute differences over every ordered pair of integers from A to B, modulo 1,000,000,007.
- Level
Medium7 of 10
- Topics
- Dynamic programming, Combinatorics, Math
- Solved
- No attempts yet
Problem
The distance between two integers is the sum of the absolute differences of their digits, compared position by position. For example, the distance between 4561 and 3278 is . When the two numbers have different lengths, the shorter one is padded with leading zeros so that the positions line up. The distance between 32 and 5678 is therefore .
Given two integers and , write a program that adds up the distance of every ordered pair in the interval . The reversed pair is counted separately, and is included as well, with distance 0.
Input
The first line contains two integers and separated by a space. ()
Output
Print the sum of the distances of all ordered pairs in the interval on the first line. The answer can grow very large, so print it modulo 1,000,000,007.