# Program to find the sum of the series 23+ 45+ 75+….. upto N terms

Last Updated : 19 Jul, 2022

Given a number N, the task is to find the Nth term of the below series:

23 + 45 + 75 + 113 + 159 +…… upto N terms

Examples:

Input: N = 4
Output: 256
Explanation:
Nth term = (2 * N * (N + 1) * (4 * N + 17) + 54 * N) / 6
= (2 * 4 * (4 + 1) * (4 * 4 + 17) + 54 * 4) / 6
= 256

Input: N = 10
Output: 2180

Approach:
The Nth term of the given series can be generalized as:

Sum of first n terms of this series:

Therefore, Sum of first n terms of this series:
Below is the implementation of the above approach:

## C++

 // CPP program to find sum// upto N-th term of the series:// 23, 45, 75, 113... #include using namespace std; // calculate Nth term of seriesint findSum(int N){    return (2 * N * (N + 1) * (4 * N + 17) + 54 * N) / 6;} // Driver Functionint main(){     // Get the value of N    int N = 4;     // 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:// 23, 45, 75, 113...import java.util.*; class solution {     static int findSum(int N){    //return the final sum    return (2 * N * (N + 1) * (4 * N + 17) + 54 * N) / 6;} //Driver programpublic static void main(String arr[]){// Get the value of N    int N = 4; // Get the sum of the series System.out.println(findSum(N)); }}

## Python3

 # Python3 program to find sum# upto N-th term of the series:# 23, 45, 75, 113... # calculate Nth term of series def findSum(N):         return (2 * N * (N + 1) * (4 * N + 17) + 54 * N) / 6     #Driver Functionif __name__=='__main__':#Get the value of N    N = 4 #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: // 23, 45, 75, 113... using System;  class GFG {      static int findSum(int N) {     //return the final sum     return (2 * N * (N + 1) *            (4 * N + 17) + 54 * N) / 6; }  // Driver Code static void Main() {     // Get the value of N     int N = 4;          // Get the sum of the series     Console.Write(findSum(N)); } }  // This code is contributed by Raj

## PHP

 

## Javascript

 

Output:
256

Time Complexity: O(1)

Auxiliary Space: O(1) since using constant variables

Previous
Next