Created
December 8, 2018 16:32
-
-
Save ryupy/594aff4c7cef5610d36ea132c2e8a9fe to your computer and use it in GitHub Desktop.
ABC 115 ref: https://qiita.com/ryupy/items/f974b93d6c2407d47531
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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