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
例如:353%3 = (300 % 3 + 50 % 3 + 3 % 3) % 3 = 2
贴出代码:
#include <iostream>
#include <string>
using namespace std;
int main()
{
string str;
int m;
while (cin >> str >> m)
{
int ans = 0;
for (int i= 0; i < str.size(); i++)
{
ans = (ans * 10 + (str[i]-'0') % m) % m;
}
cout << ans << endl;
}
return 0;
}