luogu#P9573. 「TAOI-2」核心共振
「TAOI-2」核心共振
Background
⚡Surpass all and shock mortals.⚡
⚡Bring the final divine descent of machinery.⚡
⚡The power of the storm fills the whole body.⚡
⚡The last strike, core resonance.⚡
Problem Description
Given positive integers and . For a permutation, we say that two adjacent elements produce "resonance" if and only if the sum of these two numbers is a multiple of .
Please construct a permutation of to maximize the number of "resonances" that occur. If there are multiple solutions, output any one.
Input Format
This problem has multiple test cases.
The first line of input contains a positive integer , representing the number of test cases.
For each test case, the input contains one line with two positive integers and separated by spaces.
Output Format
For each test case, output one line containing positive integers separated by spaces, representing the permutation you constructed.
3
9 1
5 2
1 12345
3 8 7 1 4 5 6 9 2
1 5 3 2 4
1
Hint
This problem uses bundled tests.
- Subtask 0 (15 pts): , .
- Subtask 1 (10 pts): .
- Subtask 2 (30 pts): .
- Subtask 3 (45 pts): No special constraints.
Constraints: For all testdata, , , , and .
Translated by ChatGPT 5