#P10254. 口吃
口吃
Background
There is a formal statement of the problem at the end of the description.
Problem Description
Because of practicing rap, ZHY has become a stutterer.
ZHY’s stutter is very special. Specifically, suppose ZHY wants to read a passage with characters. Then he will read the first character once, the second character twice, the third character three times, ... and the -th character times. For example, “原神启动” would be read by ZHY as “原神神启启启动动动动”.
YHZ has characters in hand. Each character has a pleasantness value set by YHZ, and forms a permutation of . Now, he wants to rearrange these characters into a passage for ZHY to read. Since YHZ likes playing Genshin Impact (Yuánshén), he requires that after rearrangement, the number of inversions in the sequence is exactly . However, YHZ has not decided the order of the characters yet, so please compute, over all possible permutations, the sum of the total pleasantness values of all characters that YHZ will hear when ZHY reads the passage in order. Obviously, if YHZ hears a character multiple times, its pleasantness value should be counted multiple times in the total.
Formal statement
A permutation of is called valid if and only if its number of inversions is exactly . Also, for a permutation , its weight is .
Given and , please compute the sum of weights of all valid permutations of , modulo .
The number of inversions of a permutation is defined as .
Input Format
One line with two integers .
Output Format
One line with one integer, the answer modulo .
3 2
22
7 5
22066
Hint
Sample explanation
There are only two valid permutations: and . Their weights are both , so the answer is .
For of the testdata, .
For of the testdata, .
For another of the testdata, .
For of the testdata, , .
Translated by ChatGPT 5