1 #include2 #include 3 int main() { 4 const int MOD = 1000000; 5 int n, s = 0; 6 //scanf("%d", &n); 7 n =10000000; 8 for (int i = 1; i <= n; i++) { 9 int factorial = 1;10 for (int j = 1; j <= i; j++)11 factorial = (factorial*j%MOD);12 s = (s + factorial) % MOD;13 }14 cout << s; 15 printf("Time used=%.2f\n", (double)clock() / CLOCKS_PER_SEC);16 17 return 0;18 }
clock()为计时函数,要引入<time.h>库 其功能为返回从程序运行开始到打印出的时间 除以常数CLOCKS_PRE_SEC后得到的值以秒为单位。