求助大佬

P1009 [NOIP1998 普及组] 阶乘之和

Magicherry0110 @ 2024-02-07 16:57:31

最后一个测试点WA了

#include<bits/stdc++.h>
using namespace std;
int n,S[90],len,tmp[90];

int main(){
    cin>>n;
    tmp[1]=1;
    for (int i=1;i<=n;i++){
        int nlen;
        nlen=(n>=10)?2:1;
        for (int j=1;j<=n;j++)
            tmp[j]*=i;
        len+=nlen;
        for (int j=1;j<=len;j++){
            tmp[j+1]+=tmp[j]/10;
            tmp[j]%=10;
        }
        while (!tmp[len])
            len--;

        for (int j=1;j<=len;j++)
            S[j]+=tmp[j];
        for (int j=1;j<=len;j++){
            S[j+1]+=S[j]/10;
            S[j]%=10;
        }
    }
    for (int i=len;i>=1;i--)
        cout<<S[i];

    return 0;
}

|