luogu#P11256. [GDKOI2023 普及组] 置换
[GDKOI2023 普及组] 置换
Problem Description
Moon has recently been playing a card game called Shadowverse. During the game, Moon thought of a shuffling problem. Suppose there are cards in the deck. The label of the -th card is . We define a shuffling method as a permutation , meaning that the card in position in the deck is moved to position . Now suppose Moon shuffles the deck times using the method . Let the final permutation be , where denotes the label of the -th card after shuffling. Moon wants you to compute how many valid shuffling methods satisfy that after shuffling times, the result becomes permutation . Since the answer may be very large, you only need to output the answer modulo .
Formally, for a permutation and a permutation , define their product as:
The -th power of permutation is the product of copies of . Now given a permutation and a positive integer , compute the number of permutations that satisfy the equation , modulo .
Input Format
The first line contains an integer , denoting the number of testdata cases.
Each test case consists of two lines. The first line contains two positive integers , representing the length of permutations and , and that the deck is shuffled times.
The second line contains distinct positive integers from to , representing permutation .
Output Format
Output lines. Each line contains one integer, representing the number of valid shuffling methods, modulo .
1
5 6
2 1 4 3 5
2
见/example/permutation/下的
permutation1.in
见/example/permutation/下的
permutation1.out
Hint
Sample Explanation
In the sample, or . There are valid permutations in total.
Constraints
For all testdata, , , .
For of the testdata, .
For another of the testdata, only is guaranteed.
For another of the testdata, only is guaranteed.
Translated by ChatGPT 5