-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinterestingXOR.cpp
More file actions
49 lines (44 loc) · 990 Bytes
/
interestingXOR.cpp
File metadata and controls
49 lines (44 loc) · 990 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
45
46
47
48
49
#include <bits/stdc++.h>
using namespace std;
#define ll long long int
int main(){
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int T;
cin >> T;
while(T--){
ll c;
cin >> c;
ll index = 0;
ll curr = 1;
ll num1 = 0;
ll num2 = 0;
vector<int> bits;
while(c > 0){
int k = c&1;
c = c>>1;
bits.push_back(k);
}
for(int i=1;i<bits.size();i++){
curr *= 2;
}
bool flag = true;
for(int i=bits.size()-1;i>=0;i--){
if(bits[i] == 0){
num2 += curr;
num1 += curr;
}else{
if(flag == true){
num2 += curr;
flag = false;
}else{
num1 += curr;
}
}
curr/=2;
}
ll mul = num2*num1;
cout << mul << '\n';
}
return 0;
}