ภาพรวมปัญหา
หาพจน์ที่ N ของอนุกรม: 9, 33, 73, 129, ...
ตัวอย่าง
อินพุต
N = 4
เอาต์พุต
129
วิธีแก้ปัญหา
หาความต่าง:
33-9=24, 73-33=40, 129-73=56 ความต่างรอง: 16, 16 (คงที่)
เป็น Quadratic Sequence: T(N) = 8N² + 1
โค้ดตัวอย่าง
#include <iostream>
using namespace std;
int findNthTerm(int n) {
return 8 * n * n + 1;
}
int main() {
int n = 12;
cout << "The series is 9, 33, 73, 129...\n";
cout << n << "th term of the series is " << findNthTerm(n);
return 0;
}
เอาต์พุต
The series is 9, 33, 73, 129... 12th term of the series is 1153
สรุป
ความต่างรองคงที่ → พหุนามดีกรี 2 สูตร 8n² + 1