P9345 When Will the Setting Sun Return
Background
As the sun sets behind the mountains, the last ray of afterglow gradually fades away; the beautiful evening clouds eventually turn into the dark night. In this scene, waves of homesickness rise in one’s heart again and again. For a traveler far from home, even if they do not die in a foreign land, when can they return?
Description
The sunset can be viewed as a graph consisting of $n$ different colors. The $i$-th color is $a_i$, where $a$ is a permutation of length $n$.
Define the homesickness value of a permutation as follows:
+ For all $1\le i\le n$, let $b_i=\gcd(a_i,a_{i+1})$. In particular, we define $a_{n+1}=a_1$.
+ The homesickness value of permutation $a$ is the number of **distinct** elements in the sequence $b$.
Determine whether there exists a permutation $p$ of length $n$ whose homesickness value is $k$. If it exists, output any such permutation.
Input Format
**This problem contains multiple test cases.**
The first line contains a positive integer $T$, representing the number of test cases.
For each test case, one line contains two integers $n,k$.
Output Format
For each test case:
- If no such permutation exists, output one line with the string `No`.
- Otherwise, output one line with the string `Yes`, then output one line with $n$ positive integers $p_1,p_2,\dots,p_n$, representing the permutation you found.
The checker ignores the case of the strings. For example, `YES`, `yEs`, and `yes` are all considered to indicate that an answer exists.
Explanation/Hint
**[Hint]**
A permutation of length $n$ is an array in which every positive integer from $1$ to $n$ appears exactly once. For example, $[3,1,2]$ is a permutation of length $3$, while $[5,5,1,2,3]$ is not a permutation.
**[Sample 1 Explanation]**
- For the first test case, $b=[1,1,1,1,1,1,1]$, so the homesickness value of $p$ is $1$.
- For the second test case, it can be proven that no such sequence exists.
- For the third test case, $b=[1,1,3,3,1,1,2,1,5,2,1]$, which contains $4$ distinct elements — $1,2,3$ and $5$ — so the homesickness value of $p$ is $4$.
**[Constraints and Notes]**
**This problem uses bundled tests.**
- Subtask 1 (4 points): $n\le 9$, $\sum n\le 100$.
- Subtask 2 (5 points): $k=1$.
- Subtask 3 (13 points): $\sum n\le 200$.
- Subtask 4 (30 points): For all testdata, a solution is guaranteed to exist.
- Subtask 5 (48 points): No special restrictions.
For $100\%$ of the testdata, $1\le T\le 10^5$, $3\le n\le 3\times 10^5$, $1\le k\le n$, $\sum n \le 6\times 10^5$.
Translated by ChatGPT 5