#P3599. Koishi Loves Construction
Koishi Loves Construction
Description
Koishi decided to leave Gensokyo and become a math master!
Flandre heard that her math is excellent, so she gave Koishi the following construction problem:
Task 1: Determine whether it is possible, and if so construct, a permutation of of length such that its prefix sums are pairwise distinct modulo .
Task 2: Determine whether it is possible, and if so construct, a permutation of of length such that its prefix products are pairwise distinct modulo .
As usual, Koishi pretended she could not do it and came to ask you for help.
Input Format
The first line contains two integers and , denoting the task type and the number of test cases in the test point, respectively.
Then follow lines, each containing one integer for a test case.
Output Format
For the convenience of the SPJ, you must follow the format below.
For each test case, output exactly one line:
- If you believe no valid construction exists, output a single integer .
- If you believe a valid construction exists but you cannot construct it, output a single integer .
- If you believe a valid construction exists and you successfully construct it, first output a single integer , then output integers giving your construction.
Separate every two integers with a space.
1 1
8
2 8 7 6 5 4 3 2 1
2 1
11
2 1 2 3 5 10 6 7 4 9 8 11
Hint
For each test case:
- If your existence judgment is correct, you will receive of the score. If your construction satisfies the requirements or there truly is no valid construction, you will receive the remaining .
- If your existence judgment is incorrect, you will receive no points.
Test point type : points, with , . Test point type : points, with , . Test point type : points, with , . Test point type : points, with , .
For all test points, it holds that .
Translated by ChatGPT 5
京公网安备 11011102002149号