Sequence Construction

시간 제한2초메모리 제한2048 MB

요약
합이 M이고 popcount의 xor가 K인 100개 이하의 음이 아닌 정수 수열을 만들거나, 불가능하면 -1을 출력한다.
난이도

보통10점 중 7점

유형
비트 연산, 수학, 그리디, 구현
정답자
아직 제출이 없습니다

문제

Lately, the cows on Farmer John's farm have been infatuated with watching the show Apothecowry Dairies. The show revolves around a clever bovine sleuth CowCow solving problems of various kinds. Bessie found a new problem from the show, but the solution won't be revealed until the next episode in a week! Please solve the problem for her.

You are given integers MM and KK (1≤M≤109,1≤K≤31)(1 \leq M \leq 10 ^ 9, 1 \leq K \leq 31). Please choose a positive integer NN and construct a sequence aa of NN non-negative integers such that the following conditions are satisfied:

  • 1≤N≤1001 \le N \le 100
  • a_1+a_2+⋯+a_N=Ma\_1 + a\_2 + \dots + a\_N = M
  • popcount(a_1)⊕ popcount(a_2)⊕⋯⊕ popcount(a_N)=K\text{popcount}(a\_1) \oplus \text{ popcount}(a\_2) \oplus \dots \oplus \text{ popcount}(a\_N) = K

If no such sequence exists, print −1-1.

† popcount(x)\dagger \text{ popcount}(x) is the number of bits equal to 11 in the binary representation of the integer xx. For instance, the popcount of 1111 is 33 and the popcount of 1616 is 11.

†⊕\dagger \oplus is the bitwise xor operator.

The input will consist of TT (1≤T≤5⋅1031 \le T \le 5 \cdot 10^3) independent test cases.

입력

The first line contains TT.

The first and only line of each test case has MM and KK.

It is guaranteed that all test cases are unique.

출력

Output the solutions for TT test cases as follows:

If no answer exists, the only line for that test case should be −1-1.

Otherwise, the first line for that test case should be a single integer NN, the length of the sequence -- (1≤N≤1001 \le N \le 100).

The second line for that test case should contain NN space-separated integers that satisfy the conditions -- (0≤a_i≤M0 \le a\_i \le M).

예제1

  1. 예제 1

    입력
    3
    2 1
    33 5
    10 5
    
    예상 출력
    2
    2 0
    3
    3 23 7
    -1