#K83112. Sum of Geometric Sequence
Sum of Geometric Sequence
Sum of Geometric Sequence
You are given three integers: a1, an, and k. The first term of a geometric sequence is a1 and each subsequent term is obtained by multiplying the previous term by k. Only the terms that are less than or equal to an are considered. Your task is to calculate the sum of all such terms.
The formula for the geometric sequence is given by:
[ a_i = a_{1} \times k^{(i-1)} ]
Sum the terms as long as a1 \times k^{(i-1)} \leq an. Print the result to the standard output.
inputFormat
The input consists of a single line containing three space-separated integers:
- a1: The first term of the sequence.
- an: The upper bound (inclusive).
- k: The common ratio.
You can assume that a1, an, and k are positive integers.
outputFormat
The output is a single integer: the sum of all terms in the sequence that do not exceed an.
## sample2 16 2
30
</p>