Sum of GP
School Accuracy: 18.42% Submissions: 38 Points: 0

Given n, a and r as the number of terms, first term and common ratio respectively of an Geometric Progression Series. Find the sum of the series upto nth term.
 

Example 1:

Input: 3 3 2
Output: 21
Explanation: Series upto 3td term is
3 6 12, so sum will be 21.


Example 2:

Input: 3 1 2
Output: 7
Example: Series upto 3rd term is 
1 2 4, so sum will be 7.

 

Your Task:
You don't need to read or print anything. Your task is to complete the function sum_of_gp() which takes n, a and r as input parameter and returns the sum of the series.

 

Expected Time Complexity: O(1)
Expected Space Complexity: O(1)

 

Constranits:
1 <= n, a, r <= 10

to report an issue on this page.

Editorial

We strongly recommend solving this problem on your own before viewing its editorial. Do you still want to view the editorial?

Yes

All Submissions

My Submissions:

Login to access your submissions.