bnuoj 4187 GCC (数论)

http://www.bnuoj.com/bnuoj/problem_show.php?pid=4187

【题意】:如题

【题解】:取n,m的最小值进行遍历就可以了: 注意 0 1 这组测试数据

【code】:

 1 #include <iostream>
 2 #include <stdio.h>
 3 #include <string.h>
 4 #include <math.h>
 5 #include <algorithm>
 6 
 7 using namespace std;
 8 
 9 int main()
10 {
11     int t;
12     scanf("%d",&t);
13     while(t--)
14     {
15         int n,m;
16         char str[110];
17         scanf("%s%d",str,&m);
18         int len = strlen(str);
19         if(len<7)
20         {
21             sscanf(str,"%d",&n);
22             n = min(m,n);
23         }
24         else
25         {
26             n = m;
27         }
28         int i;
29         int temp = 1%m;
30         int ans = 1%m;
31         for(i=1;i<=n;i++)
32         {
33             temp = (temp*i)%m;
34             ans = (ans+temp)%m;
35         }
36         printf("%d
",ans);
37     }
38     return 0;
39 }
原文地址:https://www.cnblogs.com/crazyapple/p/3344254.html