# 实现a的b次幂
def power(a, b):
if a==0:
return -1
if b==0 and a>0:
return 1
temp = 1
while b:
if b&1:
temp *= a
a *=a
b = b>>1
return temp
print(power(3,3))
# 实现a的b次幂
def power(a, b):
if a==0:
return -1
if b==0 and a>0:
return 1
temp = 1
while b:
if b&1:
temp *= a
a *=a
b = b>>1
return temp
print(power(3,3))
785

被折叠的 条评论
为什么被折叠?