0pts, 大佬求调qwq

P1009 [NOIP1998 普及组] 阶乘之和

WindyDay @ 2023-01-02 09:30:28

```cpp #include <iostream> using namespace std; struct node { int org, add; }; node temp[205]; int ans[205]; void clear() { for(int i = 1; i <= 200; i++) { temp[i].org = 0; temp[i].org = 0; } } void once(int t) { int cur = 1; while(temp[cur].org) { int th = temp[cur].org * t; temp[cur + 1].add = th / 10; temp[cur].org = th % 10; cur++; } } void multi(int limit) { clear(); temp[1].org = 1; temp[1].add = 0; for(int i = 1; i <= limit; i++) { once(i); for(int i = 1; i <= 200; i++) { temp[i].org += temp[i].add; temp[i].add = 0; } } } void add() { int cur = 1; do { ans[cur] += (temp[cur].org + temp[cur].add); ans[cur + 1] += ans[cur] / 10; ans[cur] %= 10; cur++; } while(ans[cur]); } int main() { int n; cin >> n; for(int i = 1; i <= n; i++) { multi(i); add(); } int cur = 1; while(ans[cur] != 0) { cur++; } cur--; for(int i = cur; i >= 1; i--) { cout << ans[i]; } } ```

by xushangyou @ 2023-01-16 22:20:01


#include <iostream>
#include <cstring>
#include <cstdio>
#include <algorithm>
using namespace std;
int n;
int a[120];
int b[120];
void add(int a[],int b[]){
    int jw = 0;
    for(int i=1;i<=120;i++){
        b[i] = b[i] + a[i] + jw;
        jw = b[i] / 10;
        b[i] = b[i] % 10;
    }
}
void cheng(int a[],int c){
    int jw = 0;
    for(int i=1;i<=120;i++){
        a[i] = a[i]*c+jw;
        jw = a[i]/10;
        a[i] = a[i] % 10;
    }
}
int main(){
    cin >> n;
    a[1] = 1;
    for(int i=1;i<=n;i++){
        cheng(a,i);
        add(a,b);
    }
    bool flag = 0;
    for(int i=120;i>=1;i--){
        if(b[i]!=0)flag=1;
        if(flag) cout << b[i];
    }
    cout << endl;
    return 0;
}

by xushangyou @ 2023-01-16 22:20:52

用这个AC


by WindyDay @ 2023-01-17 20:24:30

@xushangyou 谢谢大佬awa


|