Nth Term of Geometric Progression Problem

Given the first term A, the common ratio R, and an integer N, your task is to find the Nth term of a geometric progression (GP) series.

Explanation:

The general form of a GP series is: A, A*R, A*R^2, A*R^3, ... where A is the first term and R is the common ratio.

Input:

The first line contains an integer T representing the number of queries or test cases. Each test case consists of a single line containing three space-separated integers: N, A, and R.

Output:

For each test case, return an integer denoting the Nth term of the GP series modulo 10^9 + 7.

Example:

Input:
3 
4 2 3
5 1 2
6 5 2
Output:
54
16
160
Explanation:

For the first test case: N = 4, A = 2, R = 3, the 4th term is 2*3^3 = 54.

Constraints:

  • 1 ≤ T ≤ 10
  • 1 ≤ N ≤ 10^8
  • 0 ≤ A ≤ 50
  • 0 ≤ R ≤ 100
  • Time limit: 1 second
Note:

The result should be calculated modulo 10^9 + 7 due to potential large values.

Be the first one to answer
Add answer anonymously...
Wipro Software Developer Intern Interview Questions
Stay ahead in your career. Get AmbitionBox app
qr-code
Helping over 1 Crore job seekers every month in choosing their right fit company
65 L+

Reviews

4 L+

Interviews

4 Cr+

Salaries

1 Cr+

Users/Month

Contribute to help millions

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

Follow us
  • Youtube
  • Instagram
  • LinkedIn
  • Facebook
  • Twitter