bnuoj 4187 GCC (数论)

时间:2023-03-09 08:53:06
bnuoj 4187 GCC (数论)

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

【题意】:如题

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

【code】:

 #include <iostream>
#include <stdio.h>
#include <string.h>
#include <math.h>
#include <algorithm> using namespace std; int main()
{
int t;
scanf("%d",&t);
while(t--)
{
int n,m;
char str[];
scanf("%s%d",str,&m);
int len = strlen(str);
if(len<)
{
sscanf(str,"%d",&n);
n = min(m,n);
}
else
{
n = m;
}
int i;
int temp = %m;
int ans = %m;
for(i=;i<=n;i++)
{
temp = (temp*i)%m;
ans = (ans+temp)%m;
}
printf("%d\n",ans);
}
return ;
}