这是一道水水题 不过自己还是在这调试好一会, 好吧 自己还是太生疏 水平差劲呐!这道题的就一个思想就好了 从头遍历数组, 依次保留所取数字组成的数, 当该数大于10003 时取模,继续遍历一直到最后 思想的具体体现在代码中!代码中有解释 #include<stdio.h> #include<string.h> char a[10001000];//开个大于一百万的数组 int main() { int i, t, m, length, temp1, temp2, temp3, k; scanf("%d", &t); while(t--) { scanf("%s", a); length = strlen(a); temp2 = temp1 = 0; temp3 = 0; while(temp1 < length) { if(temp2 >= 10003)//这道题的主要思想就是这 从前往后取数, 并且要与10003去比较 当大于10003时 就取余且保留 { temp2 = temp2 % 10003; } temp2 = temp2 * 10 + (a[temp1] - '0');//取余之后依旧往后遍历 直到循环结束 temp1++;//不太明白 自己随便取个数按这个思想走一遍就知道怎么回事了 } printf("%d\n", temp2 % 10003); } return 0; } //printf("%d\n", temp2 % 10003);//我最后还错在输出了,如果在这不取模,用例子10004带入试试 会发现输出结果是10004,对,如果m比10003大,循环结 //束后temp2的值比10003大最小值 你还要再取一次模