![]() |
VOOZH | about |
Given three integers the first term a, common ratio r, and position n, find the n-th term of a geometric progression.
Note: Since the result can be large, return the answer modulo 109 + 7.
Examples:
Input: a = 2, r = 2, n = 4
Output: 16
Explanation: The GP series is 2, 4, 8, 16, ... The 4th term is 16.Input: a = 4, r = 3, n=3
Output: 36
Explanation: The GP series is 4, 12, 36, 108,.. in which 36 is the 3rd term.
The n-th term can be computed manually by repeatedly multiplying the first term by the common ratio r, a total of n ā 1 times.
16
The n-th term of a geometric progression, Tn = a Ć r^(nā1), can be found by raising the common ratio to the power (nā1). Instead of multiplying repeatedly, binary exponentiation smartly breaks the power into smaller parts using squaring, making the process much faster and efficient.
16