就对一半,不用高精度就没法对吗……

P1009 [NOIP1998 普及组] 阶乘之和

huboxuan @ 2024-07-15 23:39:23

#include <bits/stdc++.h>
using namespace std;
int n;
long long s;
int main(){
    scanf("%d",&n);
    for(int i=1;i<=n;i++){
        long long factor=1;
        for(int j=1;j<=i;j++)
            factor*=j;
        s+=factor;
    }
    printf("%lld",s);
    return 0;
}

by Steve_xh @ 2024-07-16 00:15:38

@huboxuan 是


by OldDriverTree @ 2024-07-16 01:00:42

@huboxuan n 较大时显然会爆 long long,所以必须要写高精度


by luoxiaoran62 @ 2024-07-16 07:55:12

@huboxuan 这题要高精加和高精乘


by Max_hmt @ 2024-07-18 20:07:56

@huboxuan 这题数据较大,long long都爆,除了高精度我还没有想出别的办法


by Xuhappy @ 2024-07-22 16:32:20

@huboxuan 怎么解决的?求


|