Diagnostic 0 : 1
InterviewTime limit2sMemory limit1024 MB
Count integers k in [a, b] whose base-m digit sum equals n, for up to 50,000 test cases.
- Level
Medium5 of 10
- Topics
- Dynamic programming, Math
- Solved
- No attempts yet
Problem
For each positive integer with , define the function on the set of non-negative integers as follows.
Given positive integers , , , and , find the number of integers with that satisfy .
Input
The first line contains the number of test cases .
Each of the next lines contains positive integers , , , and , separated by spaces.
Output
For each test case, print on its own line the number of integers with that satisfy , using the given , , , and .