কম্পিউটার

C/C++ প্রোগ্রাম n-th টার্ম সহ সিরিজের যোগফল n^2 – (n-1)^2


গণিতে অনেক ধরনের সিরিজ আছে যেগুলো সি প্রোগ্রামিংয়ে সহজেই সমাধান করা যায়। এই প্রোগ্রামটি সি প্রোগ্রামে সিরিজের অনুসরণের যোগফল খুঁজে বের করার জন্য।

Tn = n2 - (n-1)2

Sn mod (10 9 ) হিসাবে সিরিজের সমস্ত পদের যোগফল খুঁজুন + 7) এবং,

Sn =T1 + T2 + T3 + T4 + ...... + Tn

Input: 229137999
Output: 218194447

ব্যাখ্যা

এটি পেতে Tn 2n-1 হিসাবে প্রকাশ করা যেতে পারে

আমরা জানি,

=> Tn = n2 - (n-1)2
=>Tn = n2 - (1 + n2 - 2n)
=>Tn = n2 - 1 - n2 + 2n
=>Tn = 2n - 1.
find ∑Tn.
∑Tn = ∑(2n – 1)
Reduce the above equation to,
=>∑(2n – 1) = 2*∑n – ∑1
=>∑(2n – 1) = 2*∑n – n.
here, ∑n is the sum of first n natural numbers.
As known the sum of n natural number ∑n = n(n+1)/2.
Now the equation is,
∑Tn = (2*(n)*(n+1)/2)-n = n2
The value of n2 can be large. Instead of using n2 and take the mod of the result.
So, using the property of modular multiplication for calculating n2:
(a*b)%k = ((a%k)*(b%k))%k

উদাহরণ

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

  1. C++-এ a, b, b, c, c, c… সিরিজের N-তম পদ খুঁজে বের করার প্রোগ্রাম

  2. C++ এ সিরিজ 1, 2, 11, 12, 21… এর N-তম পদ খুঁজে বের করার প্রোগ্রাম

  3. জাভা প্রোগ্রাম n^2 - (n-1)^2 হিসাবে n-তম পদ সহ সিরিজের যোগফল খুঁজে বের করতে

  4. n^2 – (n-1)^2 হিসাবে n-তম পদ সহ সিরিজের যোগফল খুঁজে বের করার জন্য পাইথন প্রোগ্রাম