Given n, we need to find sum of first n terms of the series represented as Sn = 3 + 5 + 9 + 17 + 33 … upto n

**Examples:**

Input : 2 Output : 8 3 + 5 = 8 Input : 5 Output : 67 3 + 5 + 9 + 17 + 33 = 67

Let, the nth term be denoted by tn.

This problem can easily be solved by splitting each term as follows :

Sn = 3 + 5 + 9 + 17 + 33……

Sn = (2+1) + (4+1) + (8+1) + (16+1) +……

Sn = (2+1) + (2*2+1) + (2*2*2+1) + (2*2*2*2+1) +……+ ((2*2*2..unto n times) + 1)

We observed that the nth term can be written in terms of powers of 2 and 1.

Hence, the sum of first n terms is given as follows:

Sn = (2+1) + (4+1) + (8+1) + (16+1) +……+ upto n terms

Sn = (1 + 1 + 1 + 1 + …unto n terms) + (2 + 4 + 8 + 16 + …upto nth power of 2)

In above formula,

2 + 4 + 8 + 16…. is a G.P.

It’s sum of first n terms is given by 2*(2^n-1)/(2-1) = 2^(n+1) – 2 (using G.P. formula)

Sn = n + 2*(2^n – 1)

Sn = 2^(n+1) + n -2

## C++

`// C++ program to find sum of first n terms ` `#include <bits/stdc++.h> ` `using` `namespace` `std; ` ` ` `int` `calculateSum(` `int` `n) ` `{ ` ` ` `// Sn = n*(4*n*n + 6*n - 1)/3 ` ` ` `return` `(` `pow` `(2, n + 1) + n - 2); ` `} ` ` ` `// Driver code ` `int` `main() ` `{ ` ` ` `// number of terms to be included in sum ` ` ` `int` `n = 4; ` ` ` ` ` `// find the Sn ` ` ` `cout << ` `"Sum = "` `<< calculateSum(n); ` ` ` ` ` `return` `0; ` `} ` |

*chevron_right*

*filter_none*

## Java

`// Java program to find ` `// sum of first n terms ` `import` `java.util.*; ` ` ` `class` `GFG ` `{ ` `static` `int` `calculateSum(` `int` `n) ` `{ ` ` ` `// Sn = n*(4*n*n + 6*n - 1)/3 ` ` ` `return` `((` `int` `)Math.pow(` `2` `, n + ` `1` `) + ` ` ` `n - ` `2` `); ` `} ` ` ` `// Driver Code ` `public` `static` `void` `main(String args[]) ` `{ ` ` ` `// number of terms to ` ` ` `// be included in sum ` ` ` `int` `n = ` `4` `; ` ` ` ` ` `// find the Sn ` ` ` `System.out.println(` `"Sum = "` `+ ` ` ` `calculateSum(n)); ` `} ` `} ` ` ` `// This code is contributed ` `// by Kirti_Mangal ` |

*chevron_right*

*filter_none*

## Python

`# Python program to find sum ` `# of n terms of the series ` `def` `calculateSum(n): ` ` ` ` ` `return` `(` `2` `*` `*` `(n ` `+` `1` `) ` `+` `n ` `-` `2` `) ` ` ` `# Driver Code ` ` ` `# number of terms for the sum ` `n ` `=` `4` ` ` `# find the Sn ` `print` `(` `"Sum ="` `, calculateSum(n)) ` ` ` `# This code is contributed ` `# by Surendra_Gangwar ` |

*chevron_right*

*filter_none*

## C#

`//C# program to find ` `// sum of first n terms ` `using` `System; ` ` ` `class` `GFG ` `{ ` `static` `int` `calculateSum(` `int` `n) ` `{ ` ` ` `// Sn = n*(4*n*n + 6*n - 1)/3 ` ` ` `return` `((` `int` `)Math.Pow(2, n + 1) + ` ` ` `n - 2); ` `} ` ` ` `// Driver Code ` `public` `static` `void` `Main() ` `{ ` ` ` `// number of terms to ` ` ` `// be included in sum ` ` ` `int` `n = 4; ` ` ` ` ` `// find the Sn ` ` ` `Console.WriteLine(` `"Sum = "` `+ ` ` ` `calculateSum(n)); ` `} ` `} ` ` ` `// This code is contributed ` `// by inder_verma.. ` |

*chevron_right*

*filter_none*

## PHP

`<?php ` `// PHP program to find sum ` `// of first n terms ` `function` `calculateSum( ` `$n` `) ` `{ ` ` ` `// Sn = n*(4*n*n + 6*n - 1)/3 ` ` ` `return` `(pow(2, ` `$n` `+ 1) + ` `$n` `- 2); ` `} ` ` ` `// Driver code ` ` ` `// number of terms to be ` `// included in sum ` `$n` `= 4; ` ` ` `// find the Sn ` `echo` `"Sum = "` `, calculateSum(` `$n` `); ` ` ` `// This code is contributed ` `// by inder_verma.. ` `?> ` |

*chevron_right*

*filter_none*

**Output:**

Sum = 34

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.

## Recommended Posts:

- Nth term where K+1th term is product of Kth term with difference of max and min digit of Kth term
- Sum of series till N-th term whose i-th term is i^k - (i-1)^k
- Find the Nth term of the series where each term f[i] = f[i - 1] - f[i - 2]
- Find Nth term of the series where each term differs by 6 and 2 alternately
- Nth term of a sequence formed by sum of current term with product of its largest and smallest digit
- Count sequences of length K having each term divisible by its preceding term
- Nth term of given recurrence relation having each term equal to the product of previous K terms
- Program to get the Sum of series: 1 - x^2/2! + x^4/4! -.... upto nth term
- Find sum of Series with n-th term as n^2 - (n-1)^2
- Sum of the series 1, 2, 4, 3, 5, 7, 9, 6, 8, 10, 11, 13.. till N-th term
- Program for sum of cosh(x) series upto Nth term
- Find n-th term in the series 9, 33, 73,129 ...
- Find n-th term in the series 7, 15, 32, ...
- Middle term in the binomial expansion series
- Find n-th term in series 1 2 2 3 3 3 4 4 4 4....
- Find n-th term of series 1, 3, 6, 10, 15, 21...
- n-th term in series 2, 12, 36, 80, 150....
- Find n-th term of series 2, 10, 30, 68, 130 ...
- Find n-th term of series 3, 9, 21, 41, 71...
- Program for N-th term of Geometric Progression series

If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.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.