#include <iostream>
using namespace std;
long long walkLeft(long long node, int layer, int n)
{
if(layer==n+1) return node;
return walkLeft(node*2, layer+1, n);
}
int main()
{
long long n, k;
cin >> n >> k;
if(k==1)
{
cout << "1" << '\n';
return 0;
}
k--;
int layer;
for(layer = 1;layer<=n;layer++)
{
long long maxNum = (1LL<<(layer)) - 1;
if(k<=maxNum) break;
}
//cout << layer << '\n';
long long start = (1LL<<(layer-1));
long long kLeft = k - ((1LL<<(layer-1)) - 1) - 1;
long long node = start + kLeft / 2;
if(kLeft%2!=0) node += ((1LL<<(layer-2)));
//cout << start << " " << kLeft << '\n';
//cout << node << '\n';
cout << walkLeft(node*2+1, layer+1, n) - (1LL<<n) + 1 << '\n';
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
1 ms |
292 KB |
Output is correct |
3 |
Correct |
1 ms |
292 KB |
Output is correct |
4 |
Correct |
1 ms |
204 KB |
Output is correct |
5 |
Incorrect |
1 ms |
204 KB |
Output isn't correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
1 ms |
292 KB |
Output is correct |
3 |
Correct |
1 ms |
292 KB |
Output is correct |
4 |
Correct |
1 ms |
204 KB |
Output is correct |
5 |
Incorrect |
1 ms |
204 KB |
Output isn't correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
1 ms |
292 KB |
Output is correct |
3 |
Correct |
1 ms |
292 KB |
Output is correct |
4 |
Correct |
1 ms |
204 KB |
Output is correct |
5 |
Incorrect |
1 ms |
204 KB |
Output isn't correct |