#P7120. Chino 的比赛
Chino 的比赛
Description
Chino wants to use the problems she currently has to create a mock contest. At the beginning, these problems are arranged from easy to hard.
However, because Chino is a cute girl, she will shuffle the order of these problems. Specifically, she will perform exactly an odd number of operations, and in each operation she swaps the positions of two problems. A possible mock contest is a permutation of these problems.
To evaluate how cute a mock contest is, Chino defines as the minimum number of operations needed to change the initial order into the order of this mock contest, and defines as the number of problems that stay in the same position in both the initial order and this mock contest. Then the cuteness of this mock contest is .
As usual, you are now supposed to help Chino compute the cuteness of one mock contest. Chino thinks this is not cute enough, so she wants you to compute twice the sum of the cuteness over all possible mock contests. It can be shown that this is always a non-negative integer. To avoid the answer being too large, you only need to output it modulo the prime .
Formally, for a permutation , let denote its number of fixed points, and let be the minimum number of transpositions in a decomposition of into a product of transpositions. Let the symmetric group on elements be , and the alternating group on elements be . Compute
$$2\sum_{\pi\in S_n\land\pi\notin A_n}\frac{\upsilon\left(\pi\right)}{\nu\left(\pi\right)+1}.$$This is guaranteed to be a non-negative integer. Output the answer modulo the prime .
Input Format
Input one line with two positive integers .
Output Format
Output one line with one non-negative integer, which is the sum of the cuteness over all possible mock contests of problems, modulo .
4 16777259
40
10 2147483647
17167120
10000000 998244353
3414058
Hint
Sample Explanation #1
All possible mock contest permutations of four problems are:
- , with cuteness ;
- , with cuteness ;
- , with cuteness ;
- , with cuteness ;
- , with cuteness ;
- , with cuteness ;
- , with cuteness ;
- , with cuteness ;
- , with cuteness ;
- , with cuteness ;
- , with cuteness ;
- , with cuteness .
Constraints
This problem uses bundled testdata.
For all data, , , and is a prime.
The detailed limits of each subtask are shown in the table below:
| Subtask ID | Score | ||
|---|---|---|---|
| 1 | 10 | ||
| 2 | |||
| 3 | |||
| 4 | 20 | ||
| 5 | |||
| 6 | 10 | ||
| 7 | 20 |
Faster Modulo
In this problem, you may perform a large number of modulo operations. Therefore, you can refer to several modulo optimization methods (translated from min-25's blog) to improve the efficiency of modulo operations.
Translated by ChatGPT 5
京公网安备 11011102002149号