#P9002. [RC-07] 心跳
[RC-07] 心跳
Problem Description
For a positive integer , let denote the sum of digits of in base . We say a positive integer is -good if and only if for every positive integer , we have .
Given positive integers and , compute how many positive integers are -good.
Input Format
This problem contains multiple test cases in a single test file.
The first line contains the number of test cases .
The next lines each contain two positive integers .
Output Format
Output lines. Each line contains one non-negative integer, the answer.
6
4 2
9 3
1000 2
1000 20
28238934 154154154154154
23389348458425 5
3
6
49
60
28238934
760
Hint
Sample Explanation
Here we only explain the output of the second query. In base , the digit sums of are , respectively. From this, it is easy to see that only are -good, so the output is .
Constraints
All testdata satisfy: , , .
- Subtask ( points): , .
- Subtask ( points): .
- Subtask ( points): no special constraints.
Translated by ChatGPT 5