VOOZH about

URL: https://www.geeksforgeeks.org/dsa/sum-of-an-infinite-geometric-progression-gp/

⇱ Sum of an Infinite Geometric Progression ( GP ) - GeeksforGeeks


  • Courses
  • Tutorials
  • Interview Prep

Sum of an Infinite Geometric Progression ( GP )

Last Updated : 23 Jul, 2025

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: 2

Input: A = 1, R = -0.25
Output: 0.8

Approach: The given problem can be solved based on the following observations:

  • If absolute of value of R is greater than equal to 1, then the sum will be infinite.
  • Otherwise, the sum of the Geometric series with infinite terms can be calculated using the formula

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:


Output: 
2

 

Time Complexity: O(1)
Auxiliary Space: O(1), since no extra space has been taken.

Comment