-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcode2162C.cpp
More file actions
61 lines (51 loc) · 1.01 KB
/
Copy pathcode2162C.cpp
File metadata and controls
61 lines (51 loc) · 1.01 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
/*
* Contest : Codeforces
* Problem : 2162C - Beautiful XOR
* Link : https://codeforces.com/contest/2162/problem/C
*/
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define fastio ios::sync_with_stdio(0); cin.tie(0);
void solve() {
cerr << '\n';
ll a, b;
cin >> a >> b;
if (a == b) {
cout << "0\n";
return;
}
if ((ll)log2(b) > (ll)log2(a)) {
cout << "-1\n";
return;
}
vector<ll> ans;
while (a != b) {
ll x = 0;
for (int i = 0; i <= a; i++) {
ll y = (1 << i);
if (x + y > a) break;
// bit i of B should be on
if (b & y) {
// bit i of A is off => add bit i
if (!(a & y)) x += y;
}
// bit i is off
else {
// bit i of A is on => add bit i
if (a & y) x += y;
}
}
ans.push_back(x);
a = a ^ x;
}
cout << (int)ans.size() << '\n';
for (auto &i : ans) cout << i << ' ';
cout << '\n';
}
int main() {
fastio
int tc; cin >> tc;
while (tc--) solve();
return 0;
}