1 条题解

  • 0
    @ 2025-11-3 0:17:37

    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
    5635
    时间
    1000ms
    内存
    128MiB
    难度
    1
    标签
    递交数
    11
    已通过
    5
    上传者