1 条题解

  • 0
    @ 2022-9-28 16:10:13

    方法1

    #include <bits/stdc++.h>
    using namespace std;
    int main()
    {
        int n;
        long long ans;
        cin >> n;
        ans = 0;
        for (int i = 1; i <= n; i++)
        {
            long long now = 1; // 计算 i!
            for (int j = 2; j <= i; j++)
                now *= j;
            ans += now;
        }
        cout << ans;
        return 0;
    }
    

    方法2

    #include <bits/stdc++.h>
    using namespace std;
    int main()
    {
        int n;
        long long ans, now;
        cin >> n;
        now = 1;
        ans = 1;
        for (int i = 2; i <= n; i++)
        {
            now *= i;
            ans += now;
        }
        cout << ans;
        return 0;
    }
    
    • 1

    信息

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