#C6689. Geometric Series Sum

    ID: 50476 Type: Default 1000ms 256MiB

Geometric Series Sum

Geometric Series Sum

Given three integers a, r and n, calculate the sum of the first n terms of a geometric series. The series is defined as:

\(S = a + ar + ar^2 + \cdots + ar^{n-1}\)

If \(r \neq 1\), the sum can be computed using the formula:

\(S = a \times \frac{1-r^n}{1-r}\)

If \(r = 1\), the sum is simply \(S = a \times n\).

Your program should read the inputs from stdin and output the result to stdout.

inputFormat

The input consists of a single line containing three space-separated integers: a, r, and n, where:

a: the first term of the geometric series.

r: the common ratio.

n: the number of terms to sum.

outputFormat

Output a single integer representing the sum of the first n terms of the geometric series.## sample

3 2 4
45