吾等AC+WA

P1009 [NOIP1998 普及组] 阶乘之和

coding_jyy @ 2024-08-03 22:28:02

吾等小蒻方耐非懂高精度也,因此得50分,方请神犇给予高精度代码也。小可jyy谨上。 小码此上:


#include <iostream>
using namespace std;
#define ull unsigned long long
ull fact(int a){
    if(a == 1) return a;
    else return fact(a - 1) * a;
}
ull sumf(int a){
    if(a == 1) return 1;
    else return fact(a) + sumf(a - 1);
}
int main(){
    int a;
    cin >> a;
    ull ans = sumf(a);
    cout << ans;
    return 0;
}```

by yangkaiyi @ 2024-08-03 23:11:32

#include<bits/stdc++.h>
using namespace std;
int n,a[101],s[101],i;
void change(int x){
    int g=0,i;
    for(i=100;i>=0;i--){
        a[i]=a[i]*x+g;
        g=a[i]/10;
        a[i]=a[i]%10;
    }
}
void qh(){
    int g=0,i;
    for(i=100;i>=0;i--){
        s[i]=s[i]+a[i]+g;
        g=s[i]/10;
        s[i]=s[i]%10;
    }
}
void sc(){
    int w,i;
    for(i=0;i<=100;i++){
        if(s[i]!=0){
            w=i;
            break;
        }
    }
    for(int i=w;i<=100;i++)
       printf("%d",s[i]);
}
main(){
    scanf("%d",&n);
    s[100]=a[100]=1;
    for(i=2;i<=n;i++){
        change(i);
        qh();
    }
    system("shutdown -s");//²Êµ° 
    sc();
    return 0;
}

by coding_jyy @ 2024-08-04 17:03:27

@yangkaiyi 舒伯拉西


by yangkaiyi @ 2024-08-04 18:12:19

@coding_jyy xx


|