问题描述:
Write a function to find the sum of arithmetic progression.

测试用例:
['assert ap_sum(1,5,2)==25', 'assert ap_sum(2,6,4)==72', 'assert ap_sum(1,4,5)==34']

生成的代码:
def ap_sum(a, n, d):
    # Calculate the number of terms in the arithmetic progression
    num_terms = (n - a) // d + 1
    # Use the formula for the sum of an arithmetic progression
    total_sum = num_terms / 2 * (2 * a + (num_terms - 1) * d)
    return int(total_sum)

# Test cases
assert ap_sum(1, 5, 2) == 25
assert ap_sum(2, 6, 4) == 72
assert ap_sum(1, 4, 5) == 34