N-th Term Of Geometric Progression

Find the N-th term of a Geometric Progression (GP) series given the first term A, the common ratio R, and the term position N.

Explanation:

The general form of a GP series is A, A * R, A * R^2, A * R^3, .... Your task is to compute the N-th term of this series.

Input:

T  // number of test cases
For each test case, a single line with three space-separated integers: N A R

Output:

Print the N-th term of the GP series for each test case, one per line.

Example:

Input:
2
5 2 3
4 1 2
Output:
162
8

Constraints:

  • 1 <= T <= 10
  • 1 <= N <= 108
  • 0 <= A <= 50
  • 0 <= R <= 100

Note:

As the calculated term can be very large, you must return it modulo 109 + 7.
You do not need to handle input/output, only implement the function.
AnswerBot
4mo

Calculate the N-th term of a Geometric Progression series given the first term, common ratio, and term position.

  • Iterate through each test case and apply the formula A * R^(N-1) to find the N-th term

  • Us...read more

Help your peers!
Select
Add answer anonymously...

Top Associate Software Engineer Interview Questions Asked at Nagarro

Q. Which platform do you use for coding?
Q. Given an array of size n containing numbers from 1 to n with one number missing,...read more
Q. What are some real-life applications of data structures?
Associate Software Engineer Interview Questions
Stay ahead in your career. Get AmbitionBox app
play-icon
play-icon
qr-code
Trusted by over 1.5 Crore job seekers to find their right fit company
80 L+

Reviews

10L+

Interviews

4 Cr+

Salaries

1.5 Cr+

Users

Contribute to help millions

Made with ❤️ in India. Trademarks belong to their respective owners. All rights reserved © 2025 Info Edge (India) Ltd.

Follow Us
  • Youtube
  • Instagram
  • LinkedIn
  • Facebook
  • Twitter
Profile Image
Hello, Guest
AmbitionBox Employee Choice Awards 2025
Winners announced!
awards-icon
Contribute to help millions!
Write a review
Write a review
Share interview
Share interview
Contribute salary
Contribute salary
Add office photos
Add office photos
Add office benefits
Add office benefits