题目描述
Given a permutation with size n and an integer k, you should find a permutation substitution P that {1,2,⋯,n} will become A after performing substitution P for exactly k times. Print the permutation after performing P for once on {1,2,⋯,n}. If there are multiple solutions, print any of them. If there is no solution, print “-1” in one line.
输入描述
输出描述
If there exists solutions, print n integers in one line, or print “-1” in one line.
输入
3 998244353
2 3 1
输出
3 1 2
题解
本题有两种解法:
1.逆元(一般以扩展欧几里得,费马小定理或欧拉定理,特例,打表等方法求解)
2.置换群快速幂(3.1.a中可以得到长度与指数互质时的分数幂运算的过程是,目标循环每次指针向后移k位,源循环每次向后移1位)
(以下是官方题解)