-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmexor.cpp
More file actions
44 lines (42 loc) · 757 Bytes
/
Copy pathmexor.cpp
File metadata and controls
44 lines (42 loc) · 757 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
#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define fast \
ios_base::sync_with_stdio(false); \
cin.tie(NULL);
ll solve(ll x)
{
ll c = 0;
x = x >> 1;
while (x != 0)
{
c++;
x = x >> 1;
}
return 1 << c;
}
int main()
{
fast;
ll t, x;
cin >> t;
while (t--)
{
cin >> x;
if (x == 0)
cout << 1;
else if (x == 1 || x == 2)
cout << 2;
else
{
ll ans = solve(x);
if (ans == x)
cout << x;
else if (x == 2 * ans - 1)
cout << x + 1;
else
cout << ans;
}
cout << "\n";
}
}