forked from bekiTil/Temaribet-Nextjs
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathnew.py
68 lines (65 loc) · 1.74 KB
/
new.py
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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
from collections import deque
import math
num,left,right=[int(x) for x in input().split()]
level=deque([num])
ans=[]
def getGeneratedNum(num):
if num==0 or num==1:
return 1
value=2**math.floor(math.log2(num)+1)
return value-1
temp=0
while level:
n=len(level)
temp2=temp
for _ in range(n):
value=level.popleft()
left_generated=getGeneratedNum(value//2)
print(left_generated,temp,temp2)
print(ans)
if temp2+left_generated>=right:
if (value//2)<2:
ans.append(value//2)
else:
level.append(value//2)
break
else:
if temp2+left_generated>=left:
if (value//2)<2:
ans.append(value//2)
else:
level.append(value//2)
# temp2+=left_generated
else:
temp=left
temp2+=left_generated
rem=value%2
if temp2+1==right:
ans.append(rem)
break
else:
if temp2+1>=left:
ans.append(rem)
else:
temp=left
temp2+=1
if temp2+left_generated>=right:
if (value//2)<2:
ans.append(value//2)
else:
level.append(value//2)
break
else:
if temp2+left_generated>=left:
if (value//2)<2:
ans.append(value//2)
else:
level.append(value//2)
# temp2+=left_generated
else:
temp=left
temp2+=left_generated
temp2+=1
print(level)
print(ans)
print(len(ans))