Write a program that prints all the permutations of with exactly one cycle, for a given . Assume that the content of the position of a permutation indicates “the next position to visit”.
For instance, consider the permutation . The position 1 has a 4, the position 4 has a 5, and the position 5 has a 1. Therefore, one of the cycles of this permutation is . The other two cycles are and . The permutation has the two cycles and . The permutation has only the cycle .
Input consists of a natural number .
Print all the permutations of with only one cycle.
You can print the solutions to this exercise in any order.
The judge may accept a program that generates all the permutations and, for each one, checks if it only has one cycle. However, this is not the right solution for this problem.
Author: Unknown
Translator: Carlos Molina
Generation: 2026-01-25T11:13:19.106Z
© Jutge.org, 2006–2026.
https://jutge.org