995

P1009 [NOIP1998 普及组] 阶乘之和

huyihang @ 2024-08-31 20:41:05

#include<bits/stdc++.h>
using namespace std;
int cf(int x,int y)
{
    int a[100001]={},b[100001]={},jw[100001]={},c[100001]={},i=1,j=1,op=0;
    while(x>=1){
        i++;
        a[i]=x%10;
        x/=10;
    }
    while(y>=1){
        j++;
        b[j]=y%10;
        y/=10;
    }
    int k=max(i,j);
    for(int m=1;m<=k;m++){
        c[m]=((a[m]*b[m])%10+jw[m-1])%10;
        jw[m]=(a[m]*b[m])/10;
    }
    for(int h=1;h<=k;j++){
        op=op+c[h]*10;
    }
    return op;
}
int jc(int n)
{
    if(n==1)return 1;
    return cf(n,jc(n-1));
}
int main()
{
    int n,i,s=0;
    cin>>n;
    for(i=1;i<=n;i++){
        s=s+jc(i);
    }
    cout<<s;
    return 0;
}

by hmy0213 @ 2024-08-31 20:49:26

@huyihang 输出要高精,op和s都要高精


by huyihang @ 2024-08-31 21:16:35

@hmy0213 已关


|