50分求助!!!

P1009 [NOIP1998 普及组] 阶乘之和

Kuangxirui @ 2023-06-27 12:55:20

#include<bits/stdc++.h>
#define maxn 100
struct Bigint{
  int len,a[maxn];
  Bigint(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 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>=1;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;
}
using namespace std;
int main(){
    Bigint ans(0),fac(1);
    int m;
    cin>>m;
    for(int i=1;i<=m;i++){
        fac=fac*i;
        ans=ans+fac;
    }
    ans.print();
    return 0;
}

为什么这样不行? qaq


by morningstar_sunset @ 2023-07-05 12:31:06

50分? 我拿去编译都没过,你用的哪个版本c++编译?


|