3913. 阶乘之和
Description
计算S=1!+2!+3!+...+n!的末6位(不含前导0). 这里n!表示前n个正整数的相乘积.
Input
输入整数n(1<=n<=100000).
Output
输出1!+2!+3!+...+n!的末6位(不含前导0).
Sample Input
10
Sample Output
37913
// source code of submission 966014, Zhongshan University Online Judge System
#include <iostream>
using namespace std;
int main()
{
long n,sum = 0,m = 1,k;
cin >> n;
if ( n >= 26 )
cout << 940313 << endl;
else
{
for (int i = 1;i <= n;i++)
{
m *= i;
m %= 1000000;
sum += m;
}
k = sum % 1000000;
cout << k << endl;
}
return 0;
}