Computer >> Hướng Dẫn Máy Tính >  >> Lập Trình >> C++

Số hạng thứ N của dãy 2, 12, 36, 80, 150... C++

Dãy: 2, 12, 36, 80, 150...

Công thức: aₙ = n² + n³ = n²(n+1)

Triển khai C++

#include <bits/stdc++.h>
using namespace std;

long long nthTerm(int n) {
    return 1LL * n * n * (n + 1);
}

int main() {
    cout << nthTerm(7) << endl; // 392
    return 0;
}

Kết quả

392