计算阶乘和Sum= 1!+2!+...+n! 对1000000007求模的结果C++
时间: 2023-12-07 12:38:24 浏览: 127
计算1!……+N!的阶乘和
以下是C++计算阶乘和并对1000000007求模的代码实现:
```cpp
#include <iostream>
using namespace std;
const int MOD = 1000000007;
int main() {
int n;
cin >> n;
long long sum = 0, m = 1;
for (int i = 1; i <= n; i++) {
m = (m * i) % MOD;
sum = (sum + m) % MOD;
}
cout << sum << endl;
return 0;
}
```
阅读全文