Home >Backend Development >C++ >C/C++ program to calculate the sum of a sequence where the nth term is n raised to the power 2 minus (n-1) raised to the power 2
Here we will see how to calculate the sum of a series with n-th term n2 - (n-1)2. The recursive relationship is as follows -
Tn = n2 - (n−1)2
Therefore, The series is -
We need to find S mod (109 7) where S is the sum of all terms of the given series.
#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); }
224990500
The above is the detailed content of C/C++ program to calculate the sum of a sequence where the nth term is n raised to the power 2 minus (n-1) raised to the power 2. For more information, please follow other related articles on the PHP Chinese website!