-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathChef_LUNCH_aUG1.cpp
More file actions
60 lines (59 loc) · 989 Bytes
/
Chef_LUNCH_aUG1.cpp
File metadata and controls
60 lines (59 loc) · 989 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
50
51
52
53
54
55
56
57
58
59
60
#include<bits/stdc++.h>
#define test int t;scanf("%d",&t);while(t--)
#define loop(i,a,b) for(int i=a;i<b;i+=2)
#define pii pair<int,long int>
#define ll unsigned long long int
#define pll pair<ll ,ll>
#define MOD 100000000
using namespace std;
int main()
{
test
{
int n;
ll k,index,z;
scanf("%d%lld",&n,&k);
if(n==1)
{
if(k==0)
printf("0\n");
else
printf("1\n");
}
else if(n==2)
{
if(k==0)
printf("0\n");
else if(k==2)
printf("1\n");
else if(k==3)
printf("3\n");
else
printf("2\n");
}
else
{
index=k%(1<<n-2);
// printf("index = %lld\n",index);
z=index;
if(k%2==0)
index=index/2;
else
index=index/2+(1<<n-3);
// printf("index = %lld\n",index);
//if(n==3&&k%2!=0)
//index-=1;
if(index>0)
index=(index)*4;
if(k==z)
index=index;
else if(k==z+(1<<n-1))
index=(index+1);
else if(k==z+(1<<n-2))
index=(index+2);
else
index=(index+3);
printf("%lld\n",(index));
}
}
}