http://acm.hdu.edu.cn/showproblem.php?pid=3123纯粹的数学题,当n>m时就没必要再计算了,因为下面的数模m都等于0
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#define LEN 200
int main()
{
//printf("len = %d\n", getLen(100));
int i, j;
int T;
int n, m;
char str[LEN];
long long rs;
long long multi;
scanf("%d", &T);
while(T--)
{
scanf("%s%d", str, &m);
int len1 = strlen(str);
if(len1 > 7)
n = m;
else
sscanf(str, "%d", &n);
if(n == 0)
{
printf("%d\n", 1 % m);
}
else
{
rs = 1;
multi = 1;
for(i = 1; i <= n; i++)
{
multi = (multi * i) % m;
rs = (rs + multi) % m;
}
printf("%lld\n", rs % m);
}
}
//system("pause");
return 0;
}
posted on 2012-09-04 19:34
小鼠标 阅读(146)
评论(0) 编辑 收藏 引用 所属分类:
网选训练