宝灵求助

P1009 [NOIP1998 普及组] 阶乘之和

fish_love_cat @ 2022-10-19 13:23:15

RT。。。

#include<bits/stdc++.h>
using namespace std;
string ans="0",s;
string jia(string s1,string s2){
    string ss;
    int top=0;
    int flag=0,a[505]={},b[505]={},c[505]={},s1len=s1.length(),s2len=s2.length();
    int leng=(s1len>s2len?s1len:s2len);
    for(int i=0;i<=s1len-1;i++){
        a[i]=s1[i]-'0';
    } 
    for(int i=0;i<=s2len-1;i++){
        b[i]=s2[i]-'0';
    }
    for(int i=0;i<leng;i++){
        c[i]=a[i]+b[i]+flag;
        flag=0;
        if(c[i]>9){
            flag=1;
            c[i]%=10;
        }
    }
    if(flag){
        ss+="1";
        top++;
    }
    for(int i=leng-1;i>=0;i--){
        ss[top++]=c[i]+'0';
    }
    return ss;
}
string cheng(int xx){
    string x=to_string(xx);
    int slen=s.length(),xlen=x.length();
    reverse(s.begin(),s.end());
    reverse(x.begin(),x.end());
    int a[100]={},b[100]={},c[1000]={};
    for(int i=1;i<=slen;i++){
        a[i]=s[i-1]-'0';
    }
    for(int i=1;i<=xlen;i++){
        b[i]=x[i-1]-'0';
    }
    reverse(s.begin(),s.end());
    for(int i=1;i<=slen;i++){
        for(int j=1;j<=xlen;j++){
            c[i+j-1]+=a[i]*b[j];
            c[i+j]+=c[i+j-1]/10;
            c[i+j-1]%=10;
        }
    }
    int leng=slen+xlen,top=0;
    if(c[leng]!=0) leng++;
    string ss;
    for(int i=leng-1;i>0;i--){
        ss[top++]=c[i]+'0';
    }
    s=ss;
    return s;
}
int main(){
    int n;
    cin>>n;
    s="1";
    for(int i=2;i<=n;i++){
        ans=jia(ans,cheng(i));
    }
    cout<<ans;
    return 0;
}

c⌒っ゚Д゚)っ救命


by fish_love_cat @ 2022-10-19 13:25:11

这个玩楞他不会输出……


by cute_overmind @ 2022-10-19 13:44:35

#include<iostream>
using namespace std;
string a[60]={"0","1","3","9","33","153","873","5913","46233","409113","4037913","43954713","522956313","6749977113","93928268313","1401602636313","22324392524313","378011820620313","6780385526348313","128425485935180313","2561327494111820313","53652269665821260313","1177652997443428940313","27029669736328405580313","647478071469567844940313","16158688114800553828940313","419450149241406189412940313","11308319599659758350180940313","316196664211373618851684940313","9157958657951075573395300940313","274410818470142134209703780940313","8497249472648064951935266660940313","271628086406341595119153278820940313","8954945705218228090637347680100940313","304187744744822368938255957323620940313","10637335711130967298604907294846820940313","382630662501032184766604355445682020940313","14146383753727377231082583937026584420940313","537169001220328488991089808037100875620940313","20935051082417771847631371547939998232420940313","836850334330315506193242641144055892504420940313","34289376947494122614363304694584807557656420940313","1439295494700374021157505910939096377494040420940313","61854558558074209658512637979453093884758552420940313","2720126133346522977702138448994068984204397080420940313","122342346998826717539665299944651784048588130840420940313","5624964506810915667389970728744906677010239883800420940313","264248206017979096310354325882356886646207872272920420940313","12678163798554051767172643373255731925167694226950680420940313","620960027832821612639424806694551108812720525606160920420940313","31035053229546199656252032972759319953190362094566672920420940313"};
int main()
{
    int n;
    cin >> n;
    cout << a[n];
}

可以试着打表哦,亲。

by fish_love_cat @ 2022-10-19 13:48:29

!!!

DALAO nb

除了NB我还能说啥……


|