Run ID 作者 问题 语言 测评结果 分数 时间 内存 代码长度 提交时间
322640 詹建泽榆 【C6-4】求2+2*2+2*2*2+…+2*2*2*….*2 Python3 解答错误 0 46 MS 3728 KB 531 2025-05-17 10:21:49

Tests(0/1):


def calculate_series(n): """ 计算 2 + 2*2 + 2*2*2 + ... + 2^n 的和 参数: n (int): 序列的项数 返回: int: 序列的和 """ total = 0 current_term = 1 # 初始化为1,因为第一次循环会乘以2 for _ in range(n): current_term *= 2 # 计算当前项(2^1, 2^2, ..., 2^n) total += current_term # 累加到总和 return total # 示例 n = 5 result = calculate_series(n) print(f"2 + 2*2 + 2*2*2 + ... + 2^{n} = {result}")


测评信息: