25pts求调,玄关

P1009 [NOIP1998 普及组] 阶乘之和

Mr_yang1 @ 2024-12-18 19:10:13

#include<bits/stdc++.h>
using namespace std;
string ha(string a,string b){
    string c="";
    bool carry=0;
    int res=0;
    for(int i=a.length()-1,j=b.length()-1;i>=0||j>=0;i--,j--){
        res=0;
        if(i>=0)res+=(a[i]-'0');
        if(j>=0)res+=(b[j]-'0');
        res+=int(carry),carry=res/10,c=char(res%10+'0')+c;
    }
    if(carry)c='1'+c;
    return c;
}
string hm(string a,string b){
    string c="";
    int res[4001];memset(res,0,4000);
    for(int i=a.length()-1;i>=0;i--){
        for(int j=b.length()-1;j>=0;j--){
            int pro=(a[i]-'0')*(b[j]-'0'),p1=i+j+1,p2=p1-1;
            pro+=res[p1],res[p1]=pro%10,res[p2]+=pro/10;
        }
    }
    bool f=1;
    int l=a.length()+b.length();
    for(int i=0;i<l;i++)c+=char(res[i]+'0');
    while(c[0]=='0'&&c.length()>1)c.erase(0,1);
    return c;
}
int n; 
string s;
int main(){
    cin>>n;
    for(int i=1;i<=n;i++){
        string xs="1";
        for(int j=1;j<=i;j++){
            string zs="";
            int xj=j;while(xj)zs+=char(xj%10+'0'),xj/=10;
            xs=hm(xs,zs);
        }
        s=ha(s,xs);
    }
    cout<<s<<' ';
}

直接发自己代码或题解那种都是唐中唐哈


by dg114514 @ 2024-12-18 19:14:40

@Mr_yang1没试过,但是把int res[4001];放到全局试试


by Mr_yang1 @ 2024-12-18 19:41:30

@dg114514 不行哎


by dg114514 @ 2024-12-18 19:48:32

@Mr_yang1测试点2输入 10 std输出是 $4037913


by Mr_yang1 @ 2024-12-18 19:49:29

@dg114514 求大佬指点


|