Guest User

Untitled

a guest
Mar 25th, 2021
2,087
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.49 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3.  
  4. int get(int n,int k,int first,int mult,int add)
  5. {
  6. int tot = n/2 + (n & first & 1);
  7. if(k <= tot) return (k + k - first)*mult + add;
  8. else return get((n+1-first)/2,k - tot,first^(n&1),mult*2,add + mult*first - mult);
  9. }
  10.  
  11. signed main()
  12. {
  13. ios_base::sync_with_stdio(0); cin.tie(0);
  14.  
  15. int t = 1,n,k;
  16.  
  17. cin >> t;
  18.  
  19. while(t--)
  20. {
  21. cin >> n >> k;
  22. cout << get(n,k,0,1,0) << '\n';
  23. }
  24. }
Advertisement
Add Comment
Please, Sign In to add comment