問題一覧 > 通常問題

No.3123 Inversion

レベル : / AI推定難易度 : 2150 / 実行時間制限 : 1ケース 10.000秒 / メモリ制限 : 512 MB / 標準ジャッジ問題
タグ : (AC するまで非表示) / 解いたユーザー数 23
作問者 : kenken714 / テスター : ponjuice Nzt3 Naru820
お気に入りにしたユーザー ProblemId : 12108 / 自分の提出
問題文最終更新日: 2025-04-18 00:28:52
This statement was translated by AI (claude-opus-5-5, effort medium) and may contain errors or differ in nuance from the original. The original statement takes precedence. Back to the original
CPCTF 2025 : PPC (順位表) の他の問題:

Note: The time limit for this problem is $10$ seconds per $1$ case.

Problem Statement

You are given positive integers $T$ and $M$. Then, $T$ test cases are given. Solve the following problem for each of them.

For a permutation $P$ of $(1,2,...,N)$, let the score $f(P)$ be the number of distinct permutations that can be obtained by repeating the operation described below 0 or more times.

Below, the $i \,(1 \leq i \leq N)$-th element of the permutation $P$ is denoted by $P_{i}$.

  • In each operation, choose one of the following 2 procedures and perform it.

    • Replace $P$ with the permutation $R$ of $(1,2,...,N)$ satisfying $P_{R_i} = i$ for all $i = 1,2,...,N$.
    • Replace $P$ with the permutation $R$ of $(1,2,...,N)$ satisfying $R_{i} = P_{N - i + 1}$ for all $i = 1,2,...,N$.

There are $N!$ possible permutations $P$ of $(1,2,...,N)$. Find the sum of their scores $f(P)$, modulo $M$.

Constraints

  • $1 \leq T \leq 10^6$
  • $1 \leq N \leq 5 \times 10^6$
  • $1 \leq M \leq 10^9$
  • All input values are integers.

Input

The input is given from Standard Input in the following format.

$T$ $M$
$\mathrm{case}_1$
$\mathrm{case}_2$
$\vdots$
$\mathrm{case}_T$

Here, $\mathrm{case}_i$ denotes the $i$-th test case.

Each test case is given in the following format.

$N$

Output

Print the answers over $T$ lines.

On the $i \,(1 \leq i \leq T)$-th line, print the answer to the $i$-th test case.

Sample

Sample 1
Input
3 998244353
3
1
4478429
Output
20
1
722594001

When $N = 3$, performing operation 1 on the permutation $(1, 2, 3)$ yields $(1, 2, 3)$. Performing operation 2 yields $(3, 2, 1)$.

These 2 are the only permutations that can be obtained from $(1, 2, 3)$ by repeating operations 1 and 2 0 or more times. Therefore, $f((1, 2, 3)) = 2$.

By computing the other permutations in the same way, the sum of the scores is found to be $20$.

提出するには、Twitter 、GitHub、 Googleもしくは右上の雲マークをクリックしてアカウントを作成してください。