class Solution:
'''
倍增divisor,每次将结果保存到divisor_multiadd_list,
divisor_multiadd_list[k]=2^k * divisor
'''
def divide(self, dividend: int, divisor: int) -> int:
#溢出处理
if dividend==-2**31 and divisor==-1:
return 2**31-1
flag=1 if dividend^divisor >=0 else -1
dividend,divisor=abs(dividend),abs(divisor)
divisor_multiadd_list=[]
while divisor<=dividend:
divisor_multiadd_list.append(divisor)
divisor+=divisor
ans=0
for idx in range(len(divisor_multiadd_list)-1,-1,-1):
if dividend>=divisor_multiadd_list[idx]:
dividend-=divisor_multiadd_list[idx]
ans+=2**idx
return flag*ans