Buying Jewels
Contest: Codeforces Global Round 25
Difficulty rating: 2000
Tags: constructive algorithms, greedy, math

Alice has $$$n$$$ coins and wants to shop at Bob's jewelry store. Today, although Bob has not set up the store yet, Bob wants to make sure Alice will buy exactly $$$k$$$ jewels. To set up the store, Bob can erect at most $$$60$$$ stalls (each containing an unlimited amount of jewels) and set the price per jewel for each stall to be an integer number of coins between $$$1$$$ and $$$10^{18}$$$.

Fortunately, Bob knows that Alice buys greedily: and she will go to stall $$$1$$$, buy as many jewels as possible, then go to stall $$$2$$$, buy as many jewels as possible, and so on until the last stall. Knowing this, Bob can choose the number of stalls to set up, as well as set the price for each stall so that Alice buys exactly $$$k$$$ jewels. Help Bob fulfill the task, or determine if it is impossible to do so.

Note that Alice does not need to spend all her coins.

Input format:
Each test contains multiple test cases. The first line contains an integer $$$t$$$ ($$$1 \le t \le 1000$$$) — the number of test cases. The description of the test cases follows.

Each test case contains two positive integers $$$n$$$ and $$$k$$$ ($$$1 \le n, k \le 10^{18}$$$) — the number of coins Alice has and the number of jewels Bob wants Alice to have bought at the end.

Output format:
For each test case, print on one line "YES" if Bob can erect at most $$$60$$$ stalls and set the prices for the stalls such that Alice buys exactly $$$k$$$ jewels, or "NO" if it is impossible to do so.

If the answer is "YES", on the second line, print an integer $$$s$$$ ($$$1 \le s \le 60$$$) — the number of stalls to be set up by Bob. On the third line, print $$$s$$$ positive integers $$$p_1, p_2, \ldots, p_s$$$ ($$$1 \le p_i \le 10^{18})$$$ that represent such a satisfactory pricing $$$p$$$, where $$$p_i$$$ is the price per jewel for stall $$$i$$$. If there are multiple such $$$p$$$'s, print any of them.

Constraints:
Time limit: 2.0 s
Memory limit: 256.0 MB

Note:
In the first test case, at the first stall, Alice buys $$$3$$$ jewels and is left with $$$1$$$ coin. This is not enough to buy any jewels for any of the remaining stalls, so Alice buys exactly $$$3$$$ jewels at the end.

In the third test case,

- At the first stall, Alice buys $$$1$$$ jewel and is left with $$$127$$$ coins.
- At the second stall, Alice buys $$$1$$$ jewel and is left with $$$63$$$ coins.
- At the third stall, Alice buys $$$1$$$ jewel and is left with $$$31$$$ coins.
- At the fourth stall, Alice buys $$$1$$$ jewel and is left with $$$15$$$ coins.
- At the fifth stall, Alice buys $$$1$$$ jewel and is left with $$$7$$$ coins.
- At the sixth stall, Alice buys $$$1$$$ jewel and is left with $$$3$$$ coins.
- At the seventh stall, Alice buys $$$1$$$ jewel and is left with $$$1$$$ coin.
- At the eighth stall, Alice buys $$$1$$$ jewel and is left with $$$0$$$ coins.

Example input:
3
7 3
6 4
255 8

Example output:
YES
10
2 3 4 5 6 7 8 9 10 11
NO
YES
8
128 64 32 16 8 4 2 1

Editorial:
We first assume that $$$p_i \leq n$$$ for $$$1 \leq i \leq s$$$, since adding stalls with price greater than $$$n$$$ doesn't change the result.
If $$$n < k$$$ then the answer is obviously "NO". If $$$n = k$$$ then the answer is obviously "YES" — we can set up a single stall of price $$$1$$$.
Otherwise, the first stall should have price $$$p_1 \geq 2$$$. Let $$$n = p_1q + r$$$ such that $$$q$$$, $$$r$$$ are integers and $$$q \geq 1$$$, $$$0 \leq r < p_1$$$. Obviously Alice can buy at most $$$q + r$$$ jewels ($$$q$$$ from stall $$$1$$$, at most $$$r$$$ from other stalls). On the other hand:
$$$n - 2(q+r) = (p_1 - 2)q - r$$$
$$$\geq (p_1 - 2)q - p_1 + 1$$$ (since $$$r \leq p_1 - 1$$$)
$$$\geq (p_1 - 2) - p_1 + 1$$$ (since $$$q \geq 1, p_1 \geq 2$$$)
$$$= -1$$$
$$$\Rightarrow 2(q+r) \leq n + 1$$$
Thus, if $$$k < n$$$ and $$$2k > n + 1$$$, the answer is "NO". Otherwise, choosing $$$p_1 = n - k + 1$$$ and $$$p_2 = 1$$$ solves the problem (you also have the option to print $$$58$$$ random integers afterwards to test our checker!)