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

A18706. 下面代码实现了计算 xn 的快速幂算法,该算法体现的编程思想是( )。def power(x, n): if n == 0: return 1 res = power(x, n // 2) if n % 2 == 0: return res * res else: return res * res * x

单选题 困难
知识点

题目描述

下面代码实现了计算 xn 的快速幂算法,该算法体现的编程思想是(    )。

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

选项(单选)

上一题 下一题