814. Find Sum of AP Series
Given an Arithmetic Progression (A.P.), find the sum of its first n terms.
You are given:
- a ā the first term of the A.P.
- d ā the common difference between terms.
- n ā the number of terms.
Example 1:
Input: n = 4, a = 2, d = 2
Output: 20
Explanation:
Series = 2 + 4 + 6 + 8 ā Sum = 20
Example 2:
Input: n = 8, a = -2, d = 5
Output: 124
Explanation:
Series = -2 + 3 + 8 + 13 + 18 + 23 + 28 + 33 ā Sum = 124
Now Your Turn!
Pick the correct output for the given inputInput: n = 1, a = 100, d = 0
Still unsure what the problem is asking ?
Letās go through a few more examples, step by step, to make it clearer.
Constraints:
- ā10ⓠ⤠a, d ⤠10ā“
- 1 ⤠n ⤠10ā“
- The final sum will not exceed 10ā¹.