-
Notifications
You must be signed in to change notification settings - Fork 110
/
solution.cpp
46 lines (35 loc) · 907 Bytes
/
solution.cpp
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
#include <bits/stdc++.h>
using namespace std;
// Implementation part
long theGreatXor(long x) {
long count = 0, i = 0;
while(x > 0){
// on binary represtation of x
// expected result = summation of 2 power of i
// where i is index of 0's
// check if modulo == 0 then add 2 power i to previous result
if(x % 2 == 0){
count += (long)pow(2, i);
}
// update x and i
x = x / 2;
i++;
}
return count;
}
int main()
{
ofstream fout(getenv("OUTPUT_PATH"));
int q;
cin >> q;
cin.ignore(numeric_limits<streamsize>::max(), '\n');
for (int q_itr = 0; q_itr < q; q_itr++) {
long x;
cin >> x;
cin.ignore(numeric_limits<streamsize>::max(), '\n');
long result = theGreatXor(x);
fout << result << "\n";
}
fout.close();
return 0;
}