1. there is a theorem in the replacement group: If T is a replacement, E is a unit replacement, t ^ K = E, then the minimum positive integer solution of K is the least common multiple of all cycle lengths of t split.
This theorem is used to solve poj 2369 permutation.
2. t ^ K splits the replacement T with the length of L into gcd (L, k) parts, and each cycle is the subscripts I mod gcd (L, K) = 0, 1, 2... Element connection.
Power Operation of one cyclic replacement:
1. Round-Robin length and integer Power Calculation
Set T = A, T ^ K = B, and gcd (L, K) = 1, thenB [I] = A [(k + 1) * I % L]. Then we can construct t ^ K (such as L = 10, K = 3)
2. Fractional Power Calculation of the cycle length and exponent interlace (open side)
The constructor method is similar to the preceding process but is opposite to each other. However, each pointer of the target loop shifts K bits to the back, and the Source Loop moves one bits to the back each time.
ThisAlgorithmCan be used to solvePoj1721
3. When the cycle length and index are not mutually reinforcing, a single cycle cannot be open.
Multiple cyclic power operations
1. integer power: (P1 P2 p3... PN) ^ k = (P1) ^ K (P2) ^ K... (PN) ^ k independent operations are performed on different cyclic nodes. The integer power operation must produce a split effect.
Example: poj3281Leonardo's notebook determines whether a replacement is the result of a square replacement. For the given replacement, the cyclic Section with an even length must be produced by split, so it must appear in pairs, for cyclic knots with an odd length, the split may also exist independently in the original replacement.You only need to consider whether the replacement is paired.
2. Fractional Power Operation: In the square operation, we can combine K parts of loops with the same length of L in turn as an opening process. This is because such a K * l-length loop, for k POWER operations, is bound to split into such K parts each length L-cycle, so this approach is correct.
When K cycles are opened separately, K small loops are still obtained, and the result is correct.
Theorem: if we choose to merge M cycles with the same length of L as an operation process, as long as the k power of the cycle with the same length of M * l is ensured, we split ourselves into M portions, we can ensure that this practice is correct. That is, gcd (M * l, K) = M.
M is the factor of K, and gcd (L, K/m) = 1. Obviously, the sufficient condition for this formula isM is a multiple of gcd (L, K)
Algorithm:Compared with the Integer Operation, the Fractional Power Operation (open-side) is complicated. The solution is not unique in several cases. Sort and provide an O (n) algorithm that can find a correct solution.
1. M = gcd (L, K)
2. Select the cyclic staggered merge with N * m parts and N as a positive integer, and gcd (N * m, K/m) = 1 (to ensure the feasibility of step 3)
3. Open a large loop to the power of K/m
Replacement concatenation:
link: voj1049
question: Give m replicas sequentially, and use M replicas repeatedly to operate the initial sequence, ask the sequence after K replications. M <= 10, k <2 ^ 31.
first, merge the M replicas (calculate the product of the M replicas). Then, we need to perform the replacement K/m times (take the integer, if there is an remainder, you can simulate it in a few steps ). Note that any replacement can be expressed as a matrix. For example, replacing 1 2 3 4 with 3 1 2 4 is equivalent to the following matrix multiplication:
replacing K/m times is equivalent to multiplying K/M matrices. We can calculate the k/M power of the matrix in binary mode and multiply it by the initial sequence. Don't be too busy to be happy. The time of your satisfaction is the day of your destruction. Don't forget that there may be several replacements that need to be simulated in the end.
PS: a large number of references to Pan zhenhao's Research and Discussion on Rapid power operation of the replacement group. For specific examples and proofs, refer to the original article.