#P11284. 「GFOI Round 2」Strings
「GFOI Round 2」Strings
Description
Given two positive integers and .
We define a sequence of positive integers of length as "good" if and only if:
- ;
- There exists a positive integer such that: .
You need to determine how many good sequences of length exist, modulo .
Input Format
This problem has multiple test cases in a single test.
The first line contains a positive integer , indicating the number of test cases.
For each test case:
- The first line contains two positive integers and .
Output Format
For each test case, output a line containing a non-negative integer representing the answer modulo .
4
3 2
5 3
10 4
100000 998244353123456
4
117
430352
967771719
Hint
Sample Explanation
For the first test case, the good sequences of length are .
Subtasks and Constraints
| Subtask ID | Subtask Dependencies | Score | ||
|---|---|---|---|---|
| No | ||||
For all tests, it is guaranteed that:
- ;
- ;
- .
京公网安备 11011102002149号