![]() |
VOOZH | about |
Given two integers A and R, representing the first term and the common ratio of a geometric sequence, the task is to find the sum of the infinite geometric series formed by the given first term and the common ratio.
Examples:
Input: A = 1, R = 0.5
Output: 2Input: A = 1, R = -0.25
Output: 0.8
Approach: The given problem can be solved based on the following observations:
Therefore, if the absolute value of R is greater than equal to 1, then print "Infinite". Otherwise, print the value as the resultant sum.
Below is the implementation of the above approach:
2
Time Complexity: O(1)
Auxiliary Space: O(1), since no extra space has been taken.