不会高精度的话就用 unsigned long long ,因为它能够表示的最大整数是 264−1 ,而 int 只能表示 231−1 ,这样能够在不会高精度算法的前提下最接近 AC 。
#include <bits/stdc++.h>
using namespace std;
typedef unsigned long long ull;
ull fac(int n) {
ull res = 1;
for (int i = 2; i <= n; i++) res *= i;
return res;
}
int main() {
ull S = 0;
int n;
cin >> n;
for (int i = 1; i <= n; i++) S += fac(i);
cout << S;
return 0;
}
这样做至少能拿50分,但会高精度算法能AC。