atcoder#ABC282G. [ABC282G] Similar Permutation
[ABC282G] Similar Permutation
Score : points
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.
3 1 282282277
16
For instance, below is a pair of permutations that satisfies the condition.
Here, we have and , so the similarity of and is .
50 25 998244353
131276976
Print the number modulo .