def sum_gp(a, n, r):
    """
    Calculates the sum of a geometric progression series.

    Args:
        a: The first term of the series.
        n: The number of terms.
        r: The common ratio.

    Returns:
        The sum of the geometric progression.
    """
    if r == 1:
        # If the common ratio is 1, all terms are the same as the first term 'a'.
        # The sum is simply n times a.
        return n * a
    else:
        # Use the formula for the sum of a finite geometric series:
        # S_n = a * (1 - r^n) / (1 - r)
        # An equivalent form is a * (r^n - 1) / (r - 1), which can be
        # more stable numerically when r > 1.
        sum_of_series = a * (pow(r, n) - 1) / (r - 1)
        return sum_of_series