#P9007. [入门赛 #9] 最澄澈的空与海 (Hard Version)
[入门赛 #9] 最澄澈的空与海 (Hard Version)
Background
Material 1:
Please carefully compute the following expression:
You may find it hard to believe that the result of this expression is actually
Material 2:
For a positive integer , $x! = 1 \times 2 \times \cdots \times (x - 1) \times x$. We call the factorial of .
In particular, .
Obviously, “” is wrong, while “” is correct. So for the content in Material 1, some readers may think “the author made a mistake because they did not understand the priority order of , , , and .”
However, the exclamation mark in the last line of Material 1 is not punctuation, but the “factorial” mentioned in Material 2.
With this in mind, “$138 - 108 \div 6 = 5! = 1 \times 2 \times \cdots \times 5 = 120$” is clearly correct.
Problem Description
However, this problem may not be closely related to the background above.
We will give you test cases, and each test case contains a positive integer .
For each test case, please help compute the number of integer triples that satisfy the following conditions:
- , .
- and .
Since the answer may be very large, you need to output the result modulo .
It is not hard to notice that the answer may be . In that case, please handle it according to the “Output Format.”
Note that here it must satisfy , not .
Also note that here is not floor division. This clearly means you must ensure that and are integers.
Input Format
The input has lines.
The first line contains an integer .
The next lines each contain one integer .
Output Format
Output lines, each being an integer or a string.
For the -th line: if for the given on line of the input, there are infinitely many integer triples satisfying and , output inf. Otherwise, output the number of triples satisfying the conditions modulo .
3
2
3
4
1
3
6
Hint
Explanation for Sample 1
The specific triples in the sample are as follows:
| All possible triples | |
|---|---|
| $\begin{matrix}(8, 4, 2) & (5, -5, 5) & (6, 0, 3)\end{matrix}$ | |
| $\begin{matrix}(19, -95, 19) & (21, -21, 7) & (24, 0, 4) \\ (27, 9, 3) & (20, -40, 10) & (36, 24, 2)\end{matrix}$ |
Constraints
For the first of the testdata, it is guaranteed that and .
For the first of the testdata, it is guaranteed that .
For another of the testdata, it is guaranteed that .
For of the testdata, it is guaranteed that and .
Translated by ChatGPT 5