Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- using namespace std;
- int get(int n,int k,int first,int mult,int add)
- {
- int tot = n/2 + (n & first & 1);
- if(k <= tot) return (k + k - first)*mult + add;
- else return get((n+1-first)/2,k - tot,first^(n&1),mult*2,add + mult*first - mult);
- }
- signed main()
- {
- ios_base::sync_with_stdio(0); cin.tie(0);
- int t = 1,n,k;
- cin >> t;
- while(t--)
- {
- cin >> n >> k;
- cout << get(n,k,0,1,0) << '\n';
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment