测评会员优惠活动进行中 · 开通 VIP,有效期内测评不限次 VIP 优惠中 · 测评不限次 立即查看

A59450. power(x,n)函数是计算x的n次幂的函数,power(x,n)函数运用了分治算法的思想,调用power(3,3)函数的计算结果是:27 def power(x,n)

判断题

题目描述

power(x,n)函数是计算x的n次幂的函数,power(x,n)函数运用了分治算法的思想,调用power(3,3)函数的计算结果是:27

 def power(x,n):
     if n == 2:
         return x
     if n%2 == 0:
         return power(x,n//2) * power(x,n//2)
     else:
         return power(x,(n+1)//2) * power(x,(n-1)//2)

选项(单选)