异想天开

What's the true meaning of light, Could you tell me why

求余数

日期:2015-02-13 17:07:18
  
最后更新日期:2015-02-25 17:45:29
【技术】
http://acm.nyist.net/JudgeOnline/problem.php?pid=205
分析:
(a-b)mod n = (a mod n) - (b mod n)
(a+b)mod n = [(a mod n) + (b mod n)] mod n
( a*b ) mod n = ((a mod n) * (b mod n ))mod n
大数可以看成1234,那么1*10^3+2*10^2+3*10^1+4,可以写成迭代形式(a*10+b)*10 + b ... [code lang="cpp"]
#include<iostream>
#include<map>
#include<vector>
#include<algorithm>
#include<stdio.h>
#include<memory.h>
#include<set>
#include<string.h>

using namespace std;
const int MAX=1000000;
const int MOD=10003;
char bignum[MAX+1];

int main()
{
int c,n,m;
scanf("%d",&c);
while(c-->0){
//初始化
m=0;
scanf("%s",bignum);
n = strlen(bignum);
for(int i=0;i<n;i++){
m = (m*10 + bignum[i]-'0')% MOD;
}
printf("%d\n",m);
}
return 0;
}
[/code]