------
## 最终结论
```python
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
```