Perm Query
Time limit2sMemory limit512 MB
Given a permutation whose cycles all have length at most 40, answer queries summing iterates of the permutation on an interval until the interval returns to the identity.
- Level
Hard8 of 10
- Topics
- Math, Prefix sum, Implementation, Brute force
- Solved
- No attempts yet
Problem
You are given a permutation of . You are also given queries of the form . For each query, output the result of the following pseudocode.
- Set and .
- For each , set .
- For each , set .
- If , output and stop. Otherwise, go back to step 2.
Input
The input is given in the following format.
Output
Output the answer for each query, one per line.
Constraints
- is a permutation of .
- For each , there exists some such that . Here is with appearing times.