- Trending Categories
- Data Structure
- Networking
- RDBMS
- Operating System
- Java
- iOS
- HTML
- CSS
- Android
- Python
- C Programming
- C++
- C#
- MongoDB
- MySQL
- Javascript
- PHP

- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who

# C/C++ Program to Find sum of Series with n-th term as n power of 2 - (n-1) power of 2

Here we will see how to get the sum of the series with n-th term as n2 – (n-1)2. The recurrence relation is like below −

T_{n} = n^{2} − (n−1)^{2}

So the series is −

We need to find S mod (10^{9} + 7), where S is the sum of all terms of the given series.

## Example

#include<iostream> #define X 1000000007 using namespace std; long long getSum(long long n) { return ((n % X) * (n % X)) % X; } int main() { long long n = 56789; cout << getSum(n); }

## Output

224990500

- Related Questions & Answers
- Find sum of Series with n-th term as n^2 - (n-1)^2 in C++
- Java Program to Find sum of Series with n-th term as n^2 – (n-1)^2
- C/C++ Program to Find the sum of Series with the n-th term as n^2 – (n-1)^2
- Python Program for Find sum of Series with the n-th term as n^2 – (n-1)^2
- Program to find sum of series 1*2*3 + 2*3*4+ 3*4*5 + . . . + n*(n+1)*(n+2) in C++
- C++ program to find the sum of the series 1 + 1/2^2 + 1/3^3 + …..+ 1/n^n
- Program to find N-th term of series 1, 2, 11, 12, 21… in C++
- Sum of series 1^2 + 3^2 + 5^2 + . . . + (2*n - 1)^2 in C++
- Sum of the series 2^0 + 2^1 + 2^2 +...+ 2^n in C++
- Sum of the series 1^1 + 2^2 + 3^3 + ... + n^n using recursion in C++
- Program to find sum of series 1 + 2 + 2 + 3 + 3 + 3 + .. + n in C++
- C++ Programe to find n-th term in series 1 2 2 3 3 3 4
- Sum of the series 1.2.3 + 2.3.+ … + n(n+1)(n+2) in C
- Program to find N-th term of series 0, 0, 2, 1, 4, 2, 6, 3, 8…in C++
- Sum of series 1^2 + 3^2 + 5^2 + . . . + (2*n – 1)^2

Advertisements