Circuit Connections (Circuit)
Time limit1sMemory limit1024 MB
Given a permutation a of size n and integer k, decide whether some permutation b satisfies b^k = a, and if so output any such b.
- Level
Medium7 of 10
- Topics
- Math, Combinatorics, Implementation, Number theory
- Solved
- No attempts yet
Problem
Consider an IC (integrated circuit) with inputs and outputs, as in the following figure. The inputs are numbered from left to right. Likewise, the outputs are numbered from left to right.

In this IC, each of the inputs comes out unchanged as one of the outputs, but you cannot tell which input corresponds to which output. An IC is described by listing, for outputs , the number of the input that corresponds to each output.
For example, when , there are the following 6 kinds of IC.

Here, connecting 5 copies of IC in series makes the original inputs correspond to the final outputs respectively, as in the following figure, so the result behaves the same as IC .

Given integers (), (), and a sequence of distinct integers from to , write a program that determines whether connecting copies of the same kind of IC in series can make the result behave the same as IC , and if so, outputs an IC that achieves the goal. When multiple ICs satisfy the condition, you may output any of them.
Input
The input consists of lines.
The first line contains the integers and , separated by a space.
Line () contains the integer .
Output
The program writes its result to standard output.
If connecting copies of the same kind of IC in series can make the result behave the same as IC , write an IC satisfying the condition on lines, from line 1 to line . That is, for , line contains the number of the input corresponding to output of the IC.
If connecting copies of the same kind of IC in series cannot make the result behave the same as IC , output only 1 line containing .