33 lines
588 B
C++
33 lines
588 B
C++
|
|
#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;
|
|||
|
|
}
|