Related Articles

# Program to print the Sum of series -1 + 2 + 11 + 26 + 47 +…..

• Difficulty Level : Hard
• Last Updated : 22 Mar, 2021

Given a number N, the task is to find the sum of first N number of series:

-1, 2, 11, 26, 47, 74, …..

Examples:

Input: N = 3
Output: 12
Explanation:
Sum = (N * (N + 1) * (2 * N - 5) + 4 * N) / 2
= (3 * (3 + 1) * (2 * 3 - 5) + 4 * 3) / 2
= 12

Input: N = 9
Output: 603

Approach:
The Nth term of the given series can be generalised as:
Nth term of the series  Below is the implementation of the above approach:

## C++

 // CPP program to find SUM// upto N-th term of the series:// -1, 2, 11, 26, 47, 74, ..... #include using namespace std; // calculate Nth term of seriesint findSum(int N){    return (N * (N + 1) * (2 * N - 5) + 4 * N) / 2;} // Driver Functionint main(){     // Get the value of N    int N = 3;     // Get the sum of the series    cout << findSum(N) << endl;     return 0;}

## Java

 // Java program to find SUM// upto N-th term of the series:// -1, 2, 11, 26, 47, 74, .....import java.util.*; class solution{ static int findSum(int N){ return (N * (N + 1) * (2 * N - 5) + 4 * N) / 2;} //driver functionpublic static void main(String arr[]){  // Get the value of N    int N = 3;  // Get the sum of the series   System.out.println(findSum(N)); }}//THis code is contributed by//Surendra_Gangwar

## Python3

 # Python3 program to find sum# upto N-th term of the series:# -1, 2, 11, 26, 47, 74, ..... # calculate Nth term of seriesdef findSum(N):         return ((N * (N + 1) *           (2 * N - 5) + 4 * N) / 2)     #Driver Functionif __name__=='__main__':         #Get the value of N    N = 3     #Get the sum of the series    print(findSum(N)) #this code is contributed by Shashank_Sharma

## C#

 // C# program to find SUM// upto N-th term of the series:// -1, 2, 11, 26, 47, 74, .....using System; class GFG{static int findSum(int N){    return (N * (N + 1) *           (2 * N - 5) + 4 * N) / 2;} // Driver Codestatic public void Main (){    // Get the value of N    int N = 3;         // Get the sum of the series    Console.Write(findSum(N));}} // This code is contributed by Raj

## PHP

 

## Javascript

 
Output:
12

Time Complexity: O(1)

Attention reader! Don’t stop learning now. Get hold of all the important mathematical concepts for competitive programming with the Essential Maths for CP Course at a student-friendly price. To complete your preparation from learning a language to DS Algo and many more,  please refer Complete Interview Preparation Course.

My Personal Notes arrow_drop_up