There is a sequence whose term is
Tn = n*n-(n-1)*(n-1)
Evaluate the series
Sn = T1+T2+T3+.....+Tn
Find .
Explanation:
On solving the Tn we get Tn = 2*n-1
The Sum of the series will be n*n.
Example:
Input: n = 2
Output: 4
Approach
C++
#include <bits/stdc++.h>using namespace std;#define mod 1000000007int summingSeries(long n){n = n % mod;return (n * n) % mod;}int main(){long n = 2;cout << summingSeries(n) << "\n";return 0;}
No comments:
Post a Comment