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
小鼠標 閱讀(153)
評論(0) 編輯 收藏 引用 所屬分類:
網選訓練