NYOJ 205 求余数
//10的8次方对 10003 mod 是 9 这是为什么要 乘以9了
View Code
1 #include<stdio.h>
2 #include<string.h>
3 #include<stdlib.h>
4
5 char a[1000001];
6
7 int main()
8 {
9 int t,zero,sum;
10 int num,len,i;
11 scanf("%d",&t);
12 while(t--)
13 {
14 scanf("%s",a);
15 sum=0;
16 zero = 1;
17 len = strlen(a);
18 num = len/8;
19 for(i= len-8;num;i-=8,num--)
20 {
21 sum += atol(&a[i])%10003*zero;
22 sum%=10003;
23 a[i]='\0';
24 zero = zero%10003 * 9;
25 }
26 sum+= atol(a)%10003*zero;
27 sum%=10003;
28 printf("%d\n",sum);
29 }
30 return 0;
31 }
View Code
1 #include<stdio.h>
2
3 char ch[1000001];
4
5 int main()
6 {
7 int t,i;
8 int sum;
9 scanf("%d",&t);
10 while(t--)
11 {
12 sum=0;
13 scanf("%s",ch);
14 for(i=0;ch[i]!='\0';++i)
15 {
16 sum = ((sum * 10)%10003 + ch[i]-'0')%10003;
17 }
18 printf("%d\n",sum);
19 }
20 return 0;
21 }