Giới thiệu
Cho số nguyên N. Tìm số hạng thứ N của dãy: 3, 14, 39, 84…
Ví dụ minh họa
Đầu vào
N = 4
Đầu ra
84
Giải thích
4th term = (4³ + 4² + 4) = 64 + 16 + 4 = 84
Phân tích dãy
Công thức chung: T(N) = N³ + N² + N
Chương trình minh họa
#include <iostream>
using namespace std;
int calcNthTerm(int N) {
return (N*N*N) + (N*N) + N;
}
int main() {
int N = 6;
cout << N << "th term of the series is " << calcNthTerm(N);
return 0;
}
Đầu ra
6th term of the series is 258