forked from sitz/UVa-Online-Judge
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy path10040.cpp
68 lines (63 loc) · 925 Bytes
/
10040.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
#include <bits/stdc++.h>
using namespace std;
#define REP(i, b, n) for (int i = b; i < n; i++)
#define rep(i, n) REP(i, 0, n)
#define N 2097152
int data[N] = {0};
bool used[N];
inline void construct(int n)
{
int def = (1 << n);
int div = (1 << n);
int now = div - 1;
fill(used, used + (1 << n), false);
used[now] = true;
REP(i, (1 << n) - n, (1 << n))
{
data[i] |= def;
now = (now * 2) % div;
used[now] = true;
}
REP(i, n, (1 << n) - n)
{
now = (now * 2) % div;
if (used[now] == false)//put 0
{
}
else//put 1
{
now += 1;
data[i] |= def;
}
used[now] = true;
}
}
int main()
{
REP(i, 1, 22)
{
construct(i);
}
int te;
cin >> te;
while (te--)
{
int n, k;
cin >> n >> k;
int ans = 0;
int def = (1 << n);
rep(i, n)
{
int now = (k + i) % def;
ans *= 2;
if ((data[now] & def) == 0)
;
else
{
ans++;
}
}
cout << ans << endl;
}
return 0;
}