0分?!!!!!

P1009 [NOIP1998 普及组] 阶乘之和

poordoor @ 2024-11-08 01:56:25

#include<bits/stdc++.h>
using namespace std;
string sold="1",snew,sum="1";
string jia(string s1,string s2){
    int a[255]={0},b[255]={0},c[255]={0};
    for(int i=0;i<s1.size();i++){
        a[i]=s1[s1.size()-i-1]-'0';
    }
    for(int i=0;i<s2.size();i++){
        b[i]=s2[s2.size()-i-1]-'0';
    }
    int len=s1.size();
    if(s2.size()>len)len=s2.size();
    for(int i=0;i<len;i++){
        c[i]=a[i]+b[i];
    }
    for(int i=0;i<len;i++){
        if(c[i]>=10){
            c[i+1]+=c[i]/10;
            c[i]%=10;
        }
    }
    if(c[len]!=0)len++;
    string ret="";
    for(int i=len-1;i>=0;i--){
        ret=ret+char(c[i]+'0');
    }
    return ret;
}
string cheng(string s1,string s2){
    int a[255]={0},b[255]={0},c[255]={0};
    for(int i=0;i<s1.size();i++){
        a[i]=s1[s1.size()-i-1]-'0';
    }
    for(int i=0;i<s2.size();i++){
        b[i]=s2[s2.size()-i-1]-'0';
    }
    for(int i=0;i<s1.size();i++){
        for(int j=0;j<s2.size();j++){
            c[i+j]=a[i]*b[j];
            if(c[i+j]>=10){
                c[i+j+1]+=c[i+j]/10;
                c[i+j]%=10;
            }
        }
    }
    int p=0;
    for(int i=s1.size()+s2.size();i>=0;i--){
        if(c[i]!=0){
            p=i;
            break;
        }
    }
    string ret="";
    for(int i=p;i>=0;i--){
        ret=ret+char(c[i]+'0');
    }
    return ret;
}
int main(){
    int n;
    cin>>n;
    if(n==1||n==0)cout<<1;
    for(int iw=2;iw<=n;iw++){
    string sss=to_string(iw);
    snew=cheng(sss,sold);
    sold=snew;
    sum=jia(snew,sum);
    }
    cout<<sum;
    return 0; 
}

by zjr2014 @ 2024-11-08 08:09:31

#include<bits/stdc++.h>
using namespace std;
int a[100001]={0,1},alen=1,n,sum[100001],sumlen=1,jw;
int main(){
    cin>>n;
    for(int i=1;i<=n;i++){
        jw=0; 
        for(int j=1;j<=alen;j++){
            a[j]*=i;
            a[j]+=jw;
            jw=a[j]/10;
            a[j]%=10;
        }
        while(jw>0){
            a[alen+1]+=jw;
            jw=a[alen+1]/10;
            a[alen+1]%=10;
            alen++;
        }
        sumlen=max(sumlen,alen);
        for(int j=1;j<=sumlen;j++){
            sum[j]+=a[j];
            sum[j+1]+=sum[j]/10;
            sum[j]%=10;
        }
        if(sum[sumlen+1]!=0){
            sumlen++;
        }
    }
    for(int i=sumlen;i>=1;i--){
        cout<<sum[i];
    }
    return 0;
}

@poordoor


by poordoor @ 2024-11-08 21:19:27

@zjr2014 dalao能帮我看看哪里思路错了吗没看出来


by tengyuxuan @ 2024-11-10 19:02:18


#include <bits/stdc++.h>
using namespace std;
int a[1010],b[1010],n,len;
int main(){
    cin>>n;
    a[1]=1;
    len=1;
    for(int k=1;k<=n;k++){
        for(int i=2;i<=k;i++){
            int jw=0;
            for(int j=1;j<=len;j++){
                a[j]=a[j]*i+jw;
                jw=a[j]/10;
                a[j]=a[j]%10;
            }
            while(jw){
                a[++len]=jw%10;
                jw/=10;
            }
        }

        int jw=0; 
        for(int i=1;i<=len;i++){
            b[i]+=a[i]+jw;
            jw=b[i]/10;
            b[i]=b[i]%10;
        }
        if(jw==1){
            len++;
            b[len]=1;
            jw=0;
        }
        memset(a,0,sizeof(a));
        a[1]=1;
    }
    for(int i=len;i>=1;i--){
        cout<<b[i];
    }
    return 0;
}
@[poordoor](/user/1457886)

by poordoor @ 2024-11-12 12:55:47

@tengyuxuan 看懂了,谢谢dalao


by qimao1234 @ 2024-11-15 18:21:09

@tengyuxuan 野生的义父,受我一拜! ![感谢图](屏幕截图 2024-03-19 060708)


by lly66666 @ 2024-11-17 22:19:43

from functools import reduce
print(reduce(lambda x,y:x+y,[reduce(lambda x,y:x*y,range(1,i+1)) for i in range(1, int(input())+1)]))

满分了...

额...


by lly66666 @ 2024-11-17 22:20:58

python3 c++粉崩溃两年半


|