很经典的大数取余的问题,我记得去年做过一道多校的水题,就是大数取余。稍作优化以避免超时。
但是这个题更有意思,也告诉了我一定要避免不必要的运算以避免超时= =
1 #include <iostream> 2 #include <stdio.h> 3 #include <math.h> 4 #include <algorithm> 5 #include <string.h> 6 //#include <map> 7 using namespace std; 8 char s[1000010]; 9 int main() 10 { 11 int m,ans; 12 scanf("%d",&m); 13 while(m--) 14 { 15 ans=0; 16 17 scanf("%s",s); 18 int len=strlen(s); 19 for(int i=0; i<len; i++) 20 { 21 ans=(int)((ans*10+(s[i]-'0'))%10003); 22 } 23 printf("%d\n",ans); 24 } 25 return 0; 26 }