1 条题解

  • 0
    @ 2026-4-5 20:12:10

    C++ :

    #include <iostream>
    using namespace std;
    
    int main() {
        int n;
        cin >> n;  // 读取金字塔的层数
        
        // 计算1² + 2² + ... + n²的和,使用公式n(n+1)(2n+1)/6
        int total = n * (n + 1) * (2 * n + 1) / 6;
        
        cout << total << endl;  // 输出总石块数
        return 0;
    }
    
    • 1

    信息

    ID
    617
    时间
    1000ms
    内存
    128MiB
    难度
    (无)
    标签
    递交数
    0
    已通过
    0
    上传者