29 lines
502 B
C++
29 lines
502 B
C++
|
|
#include <iostream>
|
||
|
|
|
||
|
|
using namespace std;
|
||
|
|
typedef long long LL;
|
||
|
|
int n;
|
||
|
|
|
||
|
|
//计算阶乘
|
||
|
|
LL fac(int x) {
|
||
|
|
LL res = 1;
|
||
|
|
for (int i = 1; i <= x; i++) res *= i;
|
||
|
|
return res;
|
||
|
|
}
|
||
|
|
|
||
|
|
int main() {
|
||
|
|
|
||
|
|
cin >> n;
|
||
|
|
//计算阶乘
|
||
|
|
cout << fac(n) << endl;
|
||
|
|
//计算阶乘和
|
||
|
|
LL sum = 0;
|
||
|
|
for (int i = 1; i <= n; i++) {
|
||
|
|
LL res = 1;
|
||
|
|
for (int j = 1; j <= i; ++j)
|
||
|
|
res *= j;
|
||
|
|
sum += res;
|
||
|
|
}
|
||
|
|
cout << sum << endl;
|
||
|
|
return 0;
|
||
|
|
}
|