forked from kothariji/competitive-programming
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path(CODECHEF) Interesting XOR.cpp
74 lines (64 loc) · 1.24 KB
/
(CODECHEF) Interesting XOR.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
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
// https://www.codechef.com/MARCH21C/problems/IRSTXOR?tab=statement
#include <bits/stdc++.h>
#include <string.h>
#include <algorithm>
#include <vector>
#include <set>
typedef long long ll;
#define int long long
#define endl "\n"
#define forp(i, x, t) for (int i = x; i < t; i++)
#define forn(i, t) for (int i = t; i >= 0; i--)
#define deb(x) cout << #x << " = " << x << endl
const int mod = 1e9 + 7;
using namespace std;
string binary(int n)
{
string s = bitset<64>(n).to_string();
const auto loc1 = s.find('1');
if (loc1 != string::npos)
{
return s.substr(loc1);
}
return "0";
}
void solve()
{
int n;
cin >> n;
string num = binary(n);
// cout << num << " ";
string ans = "";
forp(i, 0, num.length())
{
if (i == 0)
{
ans += '1';
}
else if (num[i] == '0')
{
ans += '1';
}
else
{
ans += '0';
}
}
// cout << ans << " ";
int final = stoi(ans, 0, 2);
cout << (final * (n ^ final));
cout << endl;
}
int32_t main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
int t = 1;
cin >> t;
while (t--)
{
solve();
}
return 0;
}