Skip to content

Instantly share code, notes, and snippets.

@ryupy
Created December 8, 2018 16:32
Show Gist options
  • Save ryupy/594aff4c7cef5610d36ea132c2e8a9fe to your computer and use it in GitHub Desktop.
Save ryupy/594aff4c7cef5610d36ea132c2e8a9fe to your computer and use it in GitHub Desktop.
N, X = map(int, input().split())
a, p = [1],[1]
for i in range(N):
a.append(a[i] * 2 + 3)
p.append(p[i] * 2 + 1)
def f(N, X):
if N == 0:
return 0 if X <= 0 else 1
elif X <= 1 + a[N-1]:
return f(N-1, X-1)
else:
return p[N-1] + 1 + f(N-1, X-2-a[N-1])
print(f(N, X))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment