#P8107. [Cnoi2021] 未来试题

[Cnoi2021] 未来试题

Background

In the duplicate-checking stage of Cnoi2021, Cirno found that in the distant future, a problem from the 2077 freshman contest of Earthworm Technology University (some unknown school from the outside world) unexpectedly had a 9%9\% similarity to a problem in this set.

Given a positive integer nn, when generating a uniformly random permutation of length nn, find the expected number of inversions in the permutation, and output the answer modulo 109+710^9+7. (2077-xidian-freshman-online Problem.D)

The answer is clearly n(n1)4\frac{n(n-1)}{4}.

As an arithmetic genius, Cirno saw it at a glance.

But there is no need to worry: colliding with a future problem does not count as a collision, so this problem appears before you.

Problem Description

You are given two positive integers n,kn,k.

For all i[0,k)\forall i \in [0,k), when generating a uniformly random permutation of length nn, compute the probability that the number of inversions in the permutation modulo kk has remainder ii. Output the answers modulo 998244353998244353.

Input Format

One line containing two integers n,kn,k.

Output Format

One line containing kk integers separated by spaces. The ii-th integer represents the probability that the number of inversions in the permutation modulo kk has remainder i1i-1.

4 5
166374059 166374059 457528662 748683265 457528662

Hint

Sample Explanation

Number of inversions Permutations
0 (1,2,3,4)(1,2,3,4)
1 (1,2,4,3)(1,3,2,4)(2,1,3,4)(1,2,4,3)(1,3,2,4)(2,1,3,4)
2 (1,3,4,2)(1,4,2,3)(2,1,4,3)(2,3,1,4)(3,1,2,4)(1,3,4,2)(1,4,2,3)(2,1,4,3)(2,3,1,4)(3,1,2,4)
3 $(1,4,3,2)(2,3,4,1)(2,4,1,3)(3,1,4,2)(3,2,1,4)(4,1,2,3)$
4 (2,4,3,1)(3,2,4,1)(3,4,1,2)(4,1,3,2)(4,2,1,3)(2,4,3,1)(3,2,4,1)(3,4,1,2)(4,1,3,2)(4,2,1,3)
5 (3,4,2,1)(4,2,3,1)(4,3,1,2)(3,4,2,1)(4,2,3,1)(4,3,1,2)
6 (4,3,2,1)(4,3,2,1)

Constraints

For 100%100\% of the testdata, it is guaranteed that 1n1051\le n\le 10^5, 2k10002\le k\le 1000.

Re-collected from XDUCPC 2021 Onsite Contest F.

Translated by ChatGPT 5