VOOZH about

URL: https://www.geeksforgeeks.org/dsa/find-nth-term-geometric-progression-series/

⇱ Program to find nth term of given Geometric Progression - GeeksforGeeks


  • Courses
  • Tutorials
  • Interview Prep

Program to find nth term of given Geometric Progression

Last Updated : 31 Mar, 2026

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.

Approach 1: Using a Loop (Naive)

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.


Output
16

Approach 2: Using Binary Exponentiation (Efficient)

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.


Output
16
Comment