求助

P1009 [NOIP1998 普及组] 阶乘之和

SARS_CoV_2 @ 2023-02-02 21:21:55

#include <bits/stdc++.h> 
using namespace std;
const int n = 100010;
int a[n],sum[n];
void carry (int s[])
{
    for (int i = 0; i < n; i++ )
    {
        if(s[i] >= 10)
        {
            s[i+1] += s[i] / 10;
            s[i] %= 10;
        }
    }
}
int main()
{
    int n;
    cin >> n;
    a[0] = 1;
    sum[0] =1;
    for (int i = 2; i <= n; i++ )
    {
        for (int j = 0; j < n; j++ )
        {
            a[j] *=  i;
            sum[j] += a[j]; 
        }
        carry(a);
        carry(sum);
    }
    bool flag = true;
    for(int i = n;i >= 0;i--)
    {
        if(flag && !a[i]) 
        {
            continue;
        }
        else
        {
            flag = false;
            cout << sum[i];
        }
    }
    return 0;
}

by SARS_CoV_2 @ 2023-02-02 21:25:43

请不要质疑我蓝名为什么做高精度,我是帮大号问的,大号被禁言了QAQ


by SARS_CoV_2 @ 2023-02-02 21:26:19

75分


|