#P2545. Geometric Sequence Sum

    ID: 15815 Type: Default 1000ms 256MiB

Geometric Sequence Sum

Geometric Sequence Sum

Given a geometric sequence with the first term a, common ratio r, and total number of terms n, compute the sum of the first n terms.

The sum S of the sequence is given by:

\[ S = \begin{cases} a \times n, & \text{if } r = 1, \\ a \times \frac{1-r^n}{1-r}, & \text{if } r \neq 1. \end{cases} \]

Your task is to output the computed sum.

inputFormat

The input consists of a single line containing three space-separated integers a, r, and n, where a is the first term of the geometric sequence, r is the common ratio, and n is the number of terms.

outputFormat

Output a single integer, the sum of the first n terms of the geometric sequence as defined above.

sample

1 1 5
5