-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathD.py
More file actions
34 lines (31 loc) · 650 Bytes
/
D.py
File metadata and controls
34 lines (31 loc) · 650 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
from os import name
import math
n, x = map(int, input().split())
an = [1]*(n+1)
anp = [1]*(n+1)
for i in range(1, n+1):
an[i] = 2*an[i-1]+3
anp[i] = 2*anp[i-1]+1
idx = n
ans = 0
while idx>=0:
if idx==0:
print(ans+anp[idx])
exit()
if x >= an[idx]-(idx-1):
print(anp[idx]+ans)
exit()
elif x==1:
print(ans)
exit()
elif x == math.ceil(an[idx]/2):
print(ans+anp[idx-1]+1)
exit()
elif x < math.ceil(an[idx]/2):
x -= 1
idx -= 1
elif x > math.ceil(an[idx]/2):
ans += anp[idx-1]+1
x -= an[idx-1]
x -= 2
idx -= 1