-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBeautifulXOR.java
More file actions
44 lines (35 loc) · 1013 Bytes
/
BeautifulXOR.java
File metadata and controls
44 lines (35 loc) · 1013 Bytes
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
import java.util.Scanner;
public class BeautifulXOR {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int t = sc.nextInt();
while (t-- > 0) {
int a = sc.nextInt();
int b = sc.nextInt();
if (a == b) {
System.out.println("0");
continue;
}
int p = 1;
while (p <= a) {
p <<= 1;
}
if (b >= p) {
System.out.println("-1");
continue;
}
int c = a ^ b;
if (c <= a) {
System.out.println("1");
System.out.println(c);
continue;
}
int intermediate_val = a | b;
int x1 = a ^ intermediate_val;
int x2 = intermediate_val ^ b;
System.out.println("2");
System.out.println(x1 + " " + x2);
}
sc.close();
}
}