#P3599. Koishi Loves Construction

    ID: 2649 远端评测题 1000ms 125MiB 尝试: 0 已通过: 0 难度: 8 上传者: 标签>数学洛谷原创Special Judge洛谷月赛

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 1n1 \dots n of length nn such that its nn prefix sums are pairwise distinct modulo nn.

Task 2: Determine whether it is possible, and if so construct, a permutation of 1n1 \dots n of length nn such that its nn prefix products are pairwise distinct modulo nn.

As usual, Koishi pretended she could not do it and came to ask you for help.

Input Format

The first line contains two integers XX and TT, denoting the task type and the number of test cases in the test point, respectively.

Then follow TT lines, each containing one integer nn 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:

  1. If you believe no valid construction exists, output a single integer 00.
  2. If you believe a valid construction exists but you cannot construct it, output a single integer 11.
  3. If you believe a valid construction exists and you successfully construct it, first output a single integer 22, then output nn 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:

  1. If your existence judgment is correct, you will receive 30%30\% of the score. If your construction satisfies the requirements or there truly is no valid construction, you will receive the remaining 70%70\%.
  2. If your existence judgment is incorrect, you will receive no points.

Test point type 11: 1010 points, with X=1X = 1, 1n101 \leq n \leq 10. Test point type 22: 4040 points, with X=1X = 1, 1n1051 \leq n \leq {10}^5. Test point type 33: 1010 points, with X=2X = 2, 1n101 \leq n \leq 10. Test point type 44: 4040 points, with X=2X = 2, 1n1051 \leq n \leq {10}^5.

For all test points, it holds that 1T101 \leq T \leq 10.

Translated by ChatGPT 5