利用 (a*b)%m = (a%m)*(b%m)%m
# include<stdio.h>
# include<math.h>
# include<stdlib.h>
# include<string.h>
# include<ctype.h>
# include<limits.h>
# include<iostream>
# include<algorithm>
using namespace std;
int main()
{
char str[1100];
long a,t,i,len;
while(cin>>str>>a)
{
for(len = strlen(str),i = 1,t = str[0] - '0';i < len; i ++)
{
t = ( (10%a)*(t%a)%a + (str[i]-'0')%a )%a;
}
printf("%d\n",t);
}
return 0;
}
posted on 2010-08-13 16:38
付翔 阅读(312)
评论(0) 编辑 收藏 引用 所属分类:
ACM 数据结构