Files
python/TangDou/LuoGuBook/第8章模拟与高精度/P1009_Prepare.cpp
HuangHai 1f397eca87 'commit'
2025-08-30 18:35:01 +08:00

33 lines
588 B
C++
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#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;
}