-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathEQBYXOR.java
116 lines (108 loc) · 2.94 KB
/
EQBYXOR.java
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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
import java.util.*;
import java.lang.*;
import java.io.*;
/* Name of the class has to be "Main" only if the class is public. */
class EQBYXOR
{
public static void main (String[] args) throws java.lang.Exception
{
// your code goes here
Scanner s = new Scanner(System.in);
int T=s.nextInt();
while(T-->0){
int a= s.nextInt();
int b=s.nextInt();
int n=s.nextInt();
int z=1;
while(z<n){
z=z*2;
}
if((a^b) == 0){
System.out.println("0");
}
else if((a^b) < n){
System.out.println("1");
}
else if((a^b) < z){
System.out.println("2");
}
else{
System.out.println("-1");
}
}
}
}
// import java.util.*;
// class EQBYXOR {
// public static long getPositionofLeftmostUnsetBit(long num)
// {
// if ((num & (num + 1)) == 0)
// {
// int pos = 0;
// while(num!=0)
// {
// num = num >> 1;
// pos++;
// }
// return pos+1;
// }
// long pos = 0;
// for (long temp = num, count = 0; temp > 0; temp >>= 1, count++)
// if ((temp & 1) == 0)
// pos = count;
// return pos+1;
// }
// public static int countUnsetBits(int num){
// int count = 0;
// for(int i=0;i<32;i++){
// if((num&(1<<i))==0)
// count++;
// }
// return count;
// }
// public static long getXorValue(long a, long b){
// long xorval = 0;
// String xorv = "";
// while(a>0||b>0)
// {
// // System.out.println(xorval);
// if(((a&1)==1 && (b&1)==1)||((a&1)==0 && (b&1)==0)){
// // xorval = xorval<<1;
// xorv ="0"+xorv;
// }
// else{
// // xorval = xorval|1;
// // xorval = xorval<<1;
// xorv = "1"+xorv;
// }
// a=a>>1;
// b=b>>1;
// }
// xorval = Integer.parseInt(xorv,2);
// return xorval;
// }
// static int count_bits(int n)
// {
// return Integer.toBinaryString(n).length();
// }
// public static void main(String[] args) {
// Scanner sc = new Scanner(System.in);
// int tc = sc.nextInt();
// while(tc-->0)
// {
// long a = sc.nextInt();
// long b = sc.nextInt();
// long n = sc.nextInt();
// if(a==b) {
// System.out.println(0);continue;
// }
// long pos = getXorValue(a,b);
// // System.out.println(pos);
// if(pos<=n)
// System.out.println(1);
// else
// System.out.println(-1);
// }
// }
// }
/* package codechef; // don't place package name! */