给定整数 和质数 。
对于一个 的排列 ,你可以进行下列操作:
可以证明任意 的排列都能通过若干次上述操作从小到大排序。
记 表示将 从小到大排序所需的最小总操作次数。
你需要求出对于所有 的排列 ,其 总和对 取模后的值。
输入一行两个整数 (,),保证 是质数。
输出一行一个整数表示 的总和对 取模后的值。
1 100009067
9
2 100000357
1689
69 999900997
193862705
In the first test case, all the permutations are:
Therefore, the answer is .
Consider a permutation of length . Each time you can do one of the following operations:
We can show that every permutation can be made sorted in increasing order using only these operations. Let's call the minimum number of these operations needed to make the permutation sorted in increasing order.
Given , find the sum of over all permutations of size .
Since the answer could be very large, output it modulo a prime .
A permutation of length is an array consisting of distinct integers from $ 1 $ to $ n $ in arbitrary order. For example, is a permutation, but is not a permutation ( appears twice in the array), and is also not a permutation ( but there is in the array).
The only line of input contains two numbers and (, ). It is guaranteed that is a prime number.
Output the answer modulo .
1 100009067
9
2 100000357
1689
69 999900997
193862705
In the first test case, all the permutations are:
Therefore, the answer is .