50 分……

P1009 [NOIP1998 普及组] 阶乘之和

winner999 @ 2024-11-23 10:51:09

#include <bits/stdc++.h>

using namespace std;
long long jc(int x) {

    long long ret = 1;
    for (int i = 1;i <= x; i++) {
        ret = ret * i;
    }
    return ret;
}
int main () {
    int n;
    cin >> n;

    int sum = 0;
    for (int i = 1;i <= n;i++) {
        long long ret1 = jc(i);

        sum +=  ret1;
    }
    printf("%d",sum);
    return 0;
}

by zh_felix @ 2024-11-23 10:54:10

可能要高精


by ___xuzhimo___ @ 2024-11-23 11:02:58

注意要高精,数据范围太大了,如果不用高精的话会爆long long 如果n\geq20long long就会爆炸


by ___xuzhimo___ @ 2024-11-23 11:04:25

更何况输出的是int类型的变量sum


|