RE求助!50pts,求大佬!

P1009 [NOIP1998 普及组] 阶乘之和

Wangyuqi2010 @ 2024-02-25 08:41:52

#include<iostream>
#include<cstdio>
#include<cstring>
#include<string>
using namespace std;
struct Big{
    int len,a[5050];
    Big(int x=0){
        memset(a,0,sizeof(a));
        for(len=1;x;len++)
            a[len]=x%10,x/10;
        len--;
    }
    int &operator[](int i){
        return a[i];
    }
    void zp(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>=1;i--)
            printf("%d",a[i]);
    }
};
Big operator+(Big a,Big b){
    Big c;
    int len=max(a.len,b.len);
    for(int i=1;i<=len;i++){
        c[i]+=a[i]+b[i];
    }
    c.zp(len+1);
    return c;
}
Big operator*(Big a,int b){
    Big c;
    int len=a.len;
    for(int i=1;i<=len;i++){
        c[i]=a[i]*b;
    }
    c.zp(len+11);
    return c;
}

int main(){
    Big ans(0),f(1);
    int k;
    cin>>k;
    for(int i=1;i<=k;i++){
        f=f*i;
        ans=ans+f;
    }
    ans.print();
    return 0;
} 

by _czx6666_ @ 2024-02-25 09:28:26

F,ans因该是数组


by _czx6666_ @ 2024-02-25 09:32:41

记得关注我


by _czx6666_ @ 2024-02-25 09:41:59

@Wangyuqi2010


|