《算法竞赛入门经典》阶乘之和(2)

#include<stdio.h>
#include<time.h>
#include<iostream>

using namespace std;

int main()
{
	const int MOD = 1000000;
	int n,S = 0, f = 1;
	cin >> n;
	for (int i = 1; i <= n; i++)
	{
		for (int j = 1; j<= i; j++)
		{
			f = f*j%MOD;
		}
		S = (S + f)%MOD;
	}
	cout << S << endl;
	cout << (double)clock() / CLOCKS_PER_SEC << endl;
	//clock()返回程序目前为止的时间
	//除以常数CLOCKS_PER_SEC(与操纵系统相关)后以“秒”为单位
	return 0;
}

猜你喜欢

转载自blog.csdn.net/qq_38734403/article/details/80417045