50分,求大佬帮忙改高精度,谢谢

P1009 [NOIP1998 普及组] 阶乘之和

gordon321 @ 2023-08-03 14:41:51

#include<bits/stdc++.h>
using namespace std;
int  jc(int a){
    int ns=1;
    for(int i=1;i<=a;i++){
        ns=ns*i;
    }
    return ns;
}
int main(){
    long long a;
    long long ans=0;
    cin>>a;
    for(int i=1;i<=a;i++){
        ans=ans+jc(i);
    }
    cout<<ans;
    return 0;
} 

by SealMoBurp @ 2023-08-03 14:42:40

使用Python


by Rieman_sum @ 2023-08-03 14:43:34

@gordon321 bdfs高精度教程


by EricWan @ 2023-08-03 14:43:42

你这是《高精度》?


by EricWan @ 2023-08-03 14:44:49

long long 肯定存不下,只少得自己写个int256


by gordon321 @ 2023-08-03 14:45:59

能不能帮忙改一下完整程序


by Zona @ 2023-08-03 14:51:54

@gordon321 建议先做P1303和P1601把高精度学了,以及右转题解区


by zlg2011111 @ 2023-08-06 16:31:18

“求助!!!只拿到50分”讨论版有代码答案


by _ant_ant @ 2023-08-09 12:24:56

@Seal_ZhouMoTong

妖妖灵,这里出了一个叛徒!


by _ant_ant @ 2023-08-09 12:26:13

《long long度》


by _ant_ant @ 2023-08-09 12:27:05

#include<bits/stdc++.h>
using namespace std;
struct Bigint{
    int len,a[101]={0};
    Bigint(int x=0){
        for(len=1;x;len++)
            a[len]=x%10,x/=10;
        len--;
    }
    int &operator[](int i){
        return a[i];
    }
    void flatten(int L){
        len=L;
        for(int i=1;i<=len;i++)
            a[i+1]+=a[i]/10,a[i]%=10;
        for(;!a[len];)
            len--;
    }
    void print(){
        for(int i=max(len,1);i;i--)
            printf("%d",a[i]);
    }
};
Bigint operator+(Bigint a,Bigint b){
    Bigint c;
    int len=max(a.len,b.len);
    for(int i=1;i<=len;i++)
        c[i]+=a[i]+b[i];
    c.flatten(len+1);
    return c;
}
Bigint operator*(Bigint a,int b){
    Bigint c;
    int len=a.len;
    for(int i=1;i<=len;i++)
        c[i]=a[i]*b;
    c.flatten(len+11);
    return c;
}
int n;
Bigint ans(0),fac(1);
int main(){
    scanf("%d",&n);
    for(int i=1;i<=n;i++){
        fac=fac*i;
        ans=ans+fac;
    }
    ans.print();
    return 0;
}

|