Long Number
Time limit1sMemory limit512 MB
Find the c-th digit of the number formed by concatenating the arithmetic sequence a, a+b, a+2b, ... with no separators.
- Level
Medium5 of 10
- Topics
- Math, Binary search, Implementation, Prefix sum
- Solved
- No attempts yet
Problem
Albert has recently taken an interest in arithmetic sequences and is making several problems about them.
First, he picks arbitrary positive integers and and defines an arithmetic sequence : . That is, , , , and so on forever.
Without much thought, Albert kept writing one after another with no spaces (from left to right), and by doing so he created an extremely long number. In the middle of this, he became curious about what digit is written at position from the leftmost end.
For example, when and , the long number Albert wrote is as follows (writing the first 21 terms of the arithmetic sequence): 123456789101112131415161718192021...
Here, the 15th digit from the left is 2 (the 2 of "12") and the 16th digit is 1 (the 1 of "13").
As another example, when and , the long number is as follows (writing the first 11 terms of the arithmetic sequence): 310172431384552596673...
Here, the 15th digit from the left is 2 (the 2 of "52") and the 16th digit is 5 (the 5 of "59").
Given , , as input, find what the -th digit is when Albert writes the arithmetic sequence consecutively with no spaces.
Input
The first line gives the number of test cases .
Each test case is given on one line with , , separated by spaces.
Output
For each test case, output the answer on one line.