You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
29 lines
502 B
29 lines
502 B
#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;
|
|
} |