Mbpp/797

✅ 完美通过 Base: PASS Plus: PASS
测试评估
指标结果
Base 测试PASS
Plus 测试PASS
代码长度485 字符
模型生成的代码 (485 字符)
def sum_in_range(l, r):
    """
    Returns the sum of all odd natural numbers within the range [l, r] inclusive.
    """
    # Find the first odd number >= l
    start = l if l % 2 == 1 else l + 1
    # Find the last odd number <= r
    end = r if r % 2 == 1 else r - 1
    
    if start > end:
        return 0
        
    # Number of odd numbers in the range
    n = (end - start) // 2 + 1
    # Sum of an arithmetic series: n * (first + last) / 2
    return n * (start + end) // 2
Base 失败测试用例
  • 无失败测试
Plus 失败测试用例
  • 无失败测试