1.题目链接:
http://acm.hdu.edu.cn/showproblem.php?pid=1212
2.思路:
利用同余定理,即:
(a+b)%c=(a%c+b%c)%c;
(a*b)%c=(a%c*b%c)%c;
3.参考代码:
///大数对小数求余的模板题
#include <stdio.h>
#include <string.h>
int mod(char* n1,int n2){ ///同余定理
int temp=0,l=strlen(n1),i;
for(i=0;i<l;i++)
{
temp=temp*10+n1[i]-'0';
temp%=n2;
}
return temp;
}
int main()
{
char s[100000];
int n;
while(~scanf("%s%d%*c",s,&n)) ///%*c表示忽略掉换行
{
printf("%d\n",mod(s,n));
}
return 0;
}