# N-th Term Of GP

Posted: 15 Oct, 2020
Difficulty: Easy

## PROBLEM STATEMENT

#### As the answer can be large enough, return the answer modulo 10^9 + 7.

##### Input format :
``````The first line of input contains an integer T denoting the number of queries or test cases.

The first line of every test case contains three single space-separated integers N, A, and R denoting the term of GP series required, the first term, and the common ratio respectively.
``````
##### Output format :
``````For each test case, print an integer denoting the Nth term of GP in a separate line.
``````
##### Note :
``````You do not need to print anything, it has already been taken care of. Just implement the given function.
``````
##### Constraints :
``````1 <= T <= 10
1 <= N <= 10^8
0 <= A <= 50
0 <= R <= 100

Time limit: 1 second
`````` Approach 1
1. The idea is to use the formulae, Nth term of GP = A*R^(N-1).
2. To calculate POW i.e R^(N-1) we will use a loop and the algorithm for the same will be as given below,
• Initialise POW = 1
• For N-1 number of times,
• POW = POW * R
3. Return A * POW.