Given Mth and Nth term of an arithmetic progression. The task is to find the sum of its first p terms.
Input: m = 6, n = 10, mth = 12, nth = 20, p = 5
Input:m = 10, n = 20, mth = 70, nth = 140, p = 4
Approach: Let a is the first term and d is the common difference of the given AP. Therefore
mth term = a + (m-1)d and nth term = a + (n-1)d
From these two equations, find the value of a and d. Now use the formula of sum of p terms of an AP.
Sum of p terms =
( p * ( 2*a + (p-1) * d ) ) / 2;
Below is the implementation of the above approach:
Attention reader! Don’t stop learning now. Get hold of all the important DSA concepts with the DSA Self Paced Course at a student-friendly price and become industry ready.
- Ratio of mth and nth terms of an A. P. with given ratio of sums
- Find Pth term of a GP if Mth and Nth terms are given
- Mth bit in Nth binary string from a sequence generated by the given operations
- Ratio of mth and nth term in an Arithmetic Progression (AP)
- Find the Mth element of the Array after K left rotations
- Mth element after K Right Rotations of an Array
- Find n terms of Fibonacci type series with given first two terms
- Sum of nth terms of Modified Fibonacci series made by every pair of two arrays
- Number of quadruples where the first three terms are in AP and last three terms are in GP
- Nth term of given recurrence relation having each term equal to the product of previous K terms
- Count the occurrence of Nth term in first N terms of Van Eck's sequence
- Find the sum of all the terms in the n-th row of the given series
- Sum of first n terms of a given series 3, 6, 11, .....
- Program to print the sum of the given nth term
- Sum of all the numbers in the Nth row of the given triangle
- Program to convert given number of days in terms of Years, Weeks and Days
- Minimum number of power terms with sum equal to n
- Find the sum of the series 1+11+111+1111+..... upto n terms
- Sum of the series 0.6, 0.06, 0.006, 0.0006, ...to n terms
- Sum of the series 0.7, 0.77, 0.777, ... upto n terms
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to firstname.lastname@example.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.