这篇博客是从旧博客 WordPress 迁移过来,内容可能存在转换异常。
题目地址: http://acm.hdu.edu.cn/showproblem.php?pid=1212
用数论的同余知识(a+b)% c == ( (a%c) + (b%c) ) % c;
//还有 (a×b)% c == ( (a%c) × (b%c) ) % c;
数论~~~ [s:24] 哥的一块漏洞。
好题! 代码:
#include
#include
using namespace std;
int main()
{
char a[1001];
int b,len,i;
while(cin>>a)
{
cin>>b;
int j=0;
len=strlen(a);
for(i=0;i<len;i++) // 精华
j=(j*10%b+(a[i]-'0')%b)%b;
cout<<j<<endl;
}
return 0;
}