แนวคิด
สมมติว่า bn เป็นลำดับของตัวเลข ซึ่งแสดงโดยความสัมพันธ์ที่เกิดซ้ำ b1 =1 และbn+1 /bn =2 n . งานของเราคือการกำหนดมูลค่าของบันทึก2 (bn ) สำหรับ n.
อินพุต
6
ผลลัพธ์
15
คำอธิบาย
บันทึก2 (bn ) =(n * (n - 1)) / 2=(6*(6-1))/2=15
อินพุต
200
ผลลัพธ์
19900
วิธีการ
bn+1 /bn =2 n
bn /bn-1 =2 n-1
.
.
.
b2 /b1 =2 1 , เราคูณทั้งหมดข้างต้นเพื่อให้ได้มา
(bn+1 /bn ).(bn /n-1 )……(b2 /b1 ) =2 n + (n-1)+……….+1
ดังนั้น bn+1 /b1 =2 n(n+1)/2
เพราะเรารู้ 1+2+3+ ………. + (n-1) + n =n(n+1)/2
ดังนั้น bn+1 =2 n(n+1)/2 . b1; สมมติค่าเริ่มต้น b1 =1
ดังนั้น bn+1 =2sup> n(n+1)/2
ตอนนี้แทน (n+1) สำหรับ n เราได้
bn =2 n(n-1)/2
เอาท่อนซุงทั้งสองข้างมา
บันทึก2 (bn ) =n(n-1)/2
ตัวอย่าง
// C++ program to find nth term of
// a given recurrence relation
#include <bits/stdc++.h>
using namespace std;
// Shows function to return required value
int sum(int n1){
// Now get the answer
int ans1 = (n1 * (n1 - 1)) / 2;
//Now return the answer
return ans1;
}
// Driver program
int main(){
// Get the value of n
// int n = 6;
int n = 200;
// Uses function call to print result
cout << sum(n);
return 0;
} ผลลัพธ์
19900