#abc282g. G - Similar Permutation
G - Similar Permutation
Score : points
问题描述
以下,我们将 的一个排列简单地称为一个排列。
对于两个排列 和 ,我们定义它们的 相似度 为满足下列条件的整数 (其中 取值范围在 到 之间)的数量:
- 。
求出相似度为 的排列对 的数量模一个素数 的结果。
以上为通义千问 qwen-max 翻译,仅供参考。
Problem Statement
Below, a permutation of is simply called a permutation.
For two permutations , let us define their similarity as the number of integers between and such that:
- .
Find the number, modulo a prime number , of pairs of permutations whose similarity is .
Constraints
- is a prime number.
- All values in the input are integers.
Input
The input is given from Standard Input in the following format:
Output
Print the answer.
Sample Input 1
3 1 282282277
Sample Output 1
16
For instance, below is a pair of permutations that satisfies the condition.
Here, we have and , so the similarity of and is .
Sample Input 2
50 25 998244353
Sample Output 2
131276976
Print the number modulo .
update @ 2024/3/10 11:51:07