50分,求助大佬!

P1009 [NOIP1998 普及组] 阶乘之和

Dear123 @ 2023-11-23 15:38:08

#include <iostream>
using namespace std;
int j(int a){
    unsigned long long b=1;
    for(int i=1;i<=a;i++){
        b*=i;
    }
    return b;
}
int main(){
    int n;
    unsigned long long S=0,a;
    cin>>n;
    for(int i=1;i<=n;i++){
        a=j(i);
        S+=a;
    }
    cout<<S;
}

by small_john @ 2023-11-23 15:48:04

@Dear123 精度炸了


by mengmeng123456 @ 2023-12-20 09:56:05

用高精度算法,这个题的答案最大差不多是一个80位的数字,unsigned long long也存不下


|