Given three integers A, D, and R representing the first term, common difference, and common ratio of an infinite Arithmetic-Geometric Progression, the task is to find the sum of the given infinite Arithmetic-Geometric Progression such that the absolute value of R is always less than 1.
Input: A = 0, D = 1, R = 0.5
Input: A = 2, D = 3, R = -0.3
Approach: An arithmetic-geometric sequence is the result of the term-by-term multiplication of the geometric progression series with the corresponding terms of an arithmetic progression series. The series is given by:
a, (a + d) * r, (a + 2 * d) * r2, (a + 3 * d) * r3, …, [a + (N − 1) * d] * r(N − 1).
The Nth term of the Arithmetic-Geometric Progression is given by:
The sum of the Arithmetic-Geometric Progression is given by:
where, |r| < 1.
Below is the implementation of the above approach:
Time Complexity: O(1)
Auxiliary Space: O(1)
Attention reader! Don’t stop learning now. Get hold of all the important mathematical concepts for competitive programming with the Essential Maths for CP Course at a student-friendly price. To complete your preparation from learning a language to DS Algo and many more, please refer Complete Interview Preparation Course.