Problem 1001 1001一直TLE实在找不到优化的方法了求大神帮帮忙

csjqing | 2016-05-15 10:46:17Author
#include<stdio.h> char str[100005]; int Hash(char *s, int a, int b); int main(){ int n,a,b; while(scanf("%d",&n)!=EOF){ scanf("%s", str); while(n--&&n>=0){ scanf("%d%d",&a,&b); printf("%d\n",Hash(str,a-1,b)); } } return 0; } int Hash(char *s, int a, int b){ int i,j; long long sum = 1; for(i=a; i < b; i++){ sum = sum * (s[i]-28); } return sum % 9973 ; }