Count the number of valid pairs of integers satisfying a divisibility-based condition, modulo a large prime.
You are given multiple test cases. For each test case, count how many ordered pairs of positive integers satisfy the problem's divisibility condition for the given parameter values. Since the answer can be very large, output it modulo .
The key challenge is to derive a counting formula rather than enumerate pairs directly.
Input Format
- The first line contains an integer — the number of test cases.
- Each test case contains the integers needed to define the counting task.
- Process each test case independently.
Output Format
For each test case, print a single integer — the number of valid pairs modulo .
Constraints
- is small enough to allow per-testcase math-based processing.
- Values are large enough that brute force enumeration is not feasible.
- Answers are taken modulo .
Example 1
Input
1 2 3
Output
6
Explanation
This illustrative example shows a case where the count can be computed from a direct formula rather than enumeration.
Premium problem context
Unlock deeper context for this problem
Premium adds guided hints, editorial links, similar variants, discussion resources, and concept maps so you can understand why a problem matters, not just solve it once.