#include<stdio.h>
#include<ctime>
int main()
{
const int MOD = 1000000;
int i, j, n, s = 0;
scanf("%d,",&n);
for(i = 1;i <= n; i ++){
int factorial = 1;
for(j = 1; j <= i;j ++)
factorial = (factorial * j % MOD);
s = (s + factorial) % MOD;
}
printf("%d\n",s);
printf("Time used = %2.1lf\n",(double)clock()/CLOCKS_PER_SEC);
return 0;
}
这是在算法经典上看到的关于程序执行时间的函数,头文件是#include<time.h>,改成c++的#include<ctime>也行人后只要在最后面加上(double)clock()/CLOCKS_PER_SEC就行了
注意每一个字符,不要多或者少写字符。