Files
python/TangDou/LuoGuBook/第8章模拟与高精度/P1009_Prepare.cpp

33 lines
588 B
C++
Raw Normal View History

2025-08-30 18:35:01 +08:00
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
//母题
//求n阶乘
LL f(int n) {
LL s = 1;
for (int i = 1; i <= n; i++) s *= i;
return s;
}
int main() {
//INT_MAX
//2147483647
// s=1!+2!+3!+...+n!
// 3!=3*2*1
// 4!=4*3*2*1 四步
// 4!=4*3! 一步,3!我知道
//20!=20*19*18*....*1
LL s = 0;
for (int i = 1; i <= 20; i++) s += f(i);
cout << s << endl;
LL t = 1;
s = 0;
for (int i = 1; i <= 20; i++) t = t * i, s += t;
cout << s << endl;
return 0;
}