二分查找变形

arr=list(map(int,input().split()))
n=arr[0]
m=arr[1]
def get_sum(s):
    total=0
    for i in range(n):
        total+=s
        s=(s+1)//2
    return total
low=1
high=m
while(low<=high):
    mid=low+(high-low)//2
    print(mid)
    if get_sum(mid)==m:
        print(mid)
        break
    elif get_sum(mid)<m:
        low=mid+1
    else:
        high=mid-1
if low>high:
    print(low-1)

相关文章:

  • 2022-02-08
  • 2021-06-05
  • 2021-09-02
  • 2022-01-01
  • 2021-10-25
  • 2022-12-23
  • 2021-06-13
  • 2022-01-08
猜你喜欢
  • 2022-12-23
  • 2021-11-08
  • 2022-12-23
  • 2021-08-22
  • 2022-12-23
  • 2021-11-11
  • 2021-10-31
相关资源
相似解决方案