#P9007. [入门赛 #9] 最澄澈的空与海 (Hard Version)

    ID: 10045 远端评测题 2000ms 512MiB 尝试: 0 已通过: 0 难度: 7 上传者: 标签>数学2023数论O2优化素数判断,质数,筛法逆元语言月赛

[入门赛 #9] 最澄澈的空与海 (Hard Version)

Background

Material 1:

Please carefully compute the following expression: 138108÷6=?138 - 108 \div 6 = ?
You may find it hard to believe that the result of this expression is actually 5!5!

Material 2:

For a positive integer xx, $x! = 1 \times 2 \times \cdots \times (x - 1) \times x$. We call x!x! the factorial of xx.
In particular, 0!=10! = 1.

Obviously, “138108÷6=5138 - 108 \div 6 = 5” is wrong, while “(138108)÷6=5(138 - 108) \div 6 = 5” 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 ++, -, ×\times, and ÷\div.”

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 TT test cases, and each test case contains a positive integer nn.

For each test case, please help compute the number of integer triples (x,y,z)(x, y, z) that satisfy the following conditions:

  1. x0x \geq 0, z1z \geq 1.
  2. xy÷z=n!x - y \div z = n! and (xy)÷z=n!n(x - y) \div z = \dfrac{n!}{n}.

Since the answer may be very large, you need to output the result modulo 998244353998244353.

It is not hard to notice that the answer may be \infty. In that case, please handle it according to the “Output Format.”

Note that here it must satisfy (xy)÷z=n!n(x - y) \div z = \dfrac{n!}{n}, not =n= n.

Also note that ÷\div here is not floor division. This clearly means you must ensure that y÷zy \div z and (xy)÷z(x - y) \div z are integers.

Input Format

The input has T+1T + 1 lines.

The first line contains an integer TT.

The next TT lines each contain one integer nn.

Output Format

Output TT lines, each being an integer or a string.

For the ii-th line: if for the given nn on line i+1i + 1 of the input, there are infinitely many integer triples (x,y,z)(x, y, z) satisfying xy÷z=n!x - y \div z = n! and (xy)÷z=n!n(x - y) \div z = \dfrac{n!}{n}, output inf. Otherwise, output the number of triples satisfying the conditions modulo 998244353998244353.

3
2
3
4
1
3
6

Hint

Explanation for Sample 1

The specific triples in the sample are as follows:

nn All possible triples
22 (2,0,2)(2, 0, 2)
33 $\begin{matrix}(8, 4, 2) & (5, -5, 5) & (6, 0, 3)\end{matrix}$
44 $\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 20%20\% of the testdata, it is guaranteed that T10T \leq 10 and n10n \leq 10.

For the first 40%40\% of the testdata, it is guaranteed that n103n \leq 10 ^ 3.

For another 20%20\% of the testdata, it is guaranteed that T=1T = 1.

For 100%100\% of the testdata, it is guaranteed that 1T1051 \leq T \leq 10 ^ 5 and 1n1061 \leq n \leq 10 ^ 6.

Translated by ChatGPT 5