1 solutions

  • 0
    @ 2025-11-27 11:54:18

    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

    Information

    ID
    24
    Time
    1000ms
    Memory
    128MiB
    Difficulty
    (None)
    Tags
    # Submissions
    0
    Accepted
    0
    Uploaded By