#P12025. Detective CowCow's Popcount Mystery

    ID: 14130 Type: Default 1000ms 256MiB

Detective CowCow's Popcount Mystery

Detective CowCow's Popcount Mystery

Farmer John’s cows have been glued to the latest episode of The Condensed Milk Detective, in which the clever bovine sleuth CowCow solves many mysterious cases. Inspired by the show, Betsy has come across a brand‐new puzzle – but the answer won’t be revealed until next week’s episode! Can you help her crack it?

You are given two integers \(M\) and \(K\) (with \(1 \le M \le 10^9\) and \(1 \le K \le 31\)). Your task is to choose a positive integer \(N\) (with \(1 \le N \le 100\)) and construct a sequence of \(N\) non‐negative integers \(a_1,a_2,\dots,a_N\) satisfying:

  • \(a_1+a_2+\cdots+a_N = M\).
  • \(\text{popcount}(a_1) \oplus \text{popcount}(a_2) \oplus \cdots \oplus \text{popcount}(a_N) = K\),

where \(\text{popcount}(x)\) denotes the number of 1’s in the binary representation of \(x\) (for example, \(\text{popcount}(11)=3\) and \(\text{popcount}(16)=1\)), and \(\oplus\) is the bitwise XOR operator.

If no such sequence exists, output -1.

The input contains \(T\) independent test cases (\(1 \le T \le 5\cdot10^3\)).

inputFormat

The first line contains an integer \(T\), the number of test cases. Each of the following \(T\) lines contains two space‐separated integers \(M\) and \(K\) (\(1 \le M \le 10^9,\ 1 \le K \le 31\)).

outputFormat

For each test case, if a valid sequence exists, output a line starting with \(N\) (\(1 \le N \le 100\)) – the length of the sequence – followed by \(N\) space‐separated non-negative integers which form the sequence. If no valid sequence exists, output -1.

sample

3
6 1
10 3
31 5
3 1 1 4

3 0 1 9 1 31

</p>