Dãy: 1, 17, 98, 354...
Quan sát: aₙ = 1⁴ + 2⁴ + 3⁴ + ... + n⁴
Công thức tổng lũy thừa 4
Σ i⁴ = n(n+1)(2n+1)(3n²+3n−1) / 30
Triển khai C++
#include <bits/stdc++.h>
using namespace std;
long long nthTerm(int n) {
// Công thức đóng
long long n2 = 1LL * n * n;
long long n3 = n2 * n;
long long n4 = n3 * n;
return n * (n + 1) * (2 * n + 1) * (3 * n2 + 3 * n - 1) / 30;
}
int main() {
cout << nthTerm(7) << endl; // 4676
return 0;
}
Kết quả
4676