fork download
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. int f(int n, int k) {
  5. if (!n) return 0;
  6. int tmp = 1 << (n - 1);
  7. if (k < tmp) return f(n - 1, k);
  8. return tmp + f(n - 1, (1 << n) - 1 - k);
  9. }
  10.  
  11. int main() {
  12. int N, n, k;
  13. cin >> N;
  14. for (int i = N; i > 0; i--) {
  15. cin >> n >> k;
  16. cout << f(n,k) << endl;
  17. }
  18. return 0;
  19. }
Success #stdin #stdout 0s 15232KB
stdin
14
1 0
1 1
2 0
2 1
2 2
2 3
3 0
3 1
3 2
3 3
3 4
3 5
3 6
3 7
stdout
0
1
0
1
3
2
0
1
3
2
6
7
5
4