CF BUDDY
← Problems·

1951D · Buying Jewels

2000 · constructive algorithms, greedy, math

Problem: Alice has nn 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 kk jewels. To set up the store, Bob can erect at most 6060 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 11 and 101810^{18}.

Fortunately, Bob knows that Alice buys greedily: and she will go to stall 11, buy as many jewels as possible, then go to stall 22, 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 kk 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 tt (1t10001 \le t \le 1000) — the number of test cases. The description of the test cases follows.

Each test case contains two positive integers nn and kk (1n,k10181 \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 6060 stalls and set the prices for the stalls such that Alice buys exactly kk jewels, or "NO" if it is impossible to do so.

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

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

In the third test case,

  • At the first stall, Alice buys 11 jewel and is left with 127127 coins.
  • At the second stall, Alice buys 11 jewel and is left with 6363 coins.
  • At the third stall, Alice buys 11 jewel and is left with 3131 coins.
  • At the fourth stall, Alice buys 11 jewel and is left with 1515 coins.
  • At the fifth stall, Alice buys 11 jewel and is left with 77 coins.
  • At the sixth stall, Alice buys 11 jewel and is left with 33 coins.
  • At the seventh stall, Alice buys 11 jewel and is left with 11 coin.
  • At the eighth stall, Alice buys 11 jewel and is left with 00 coins.

Sample Cases

Case 1

Input

3
7 3
6 4
255 8

Output

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

Similar problems

00:00:00
Loading editor…
Welcome! I'm your coding tutor for this problem. Use the chips below to reveal stored hints or get AI feedback on your code. I'll guide you step by step — never giving away the solution.

Sign in to unlock AI tutor feedback