标签:
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)
Total Submission(s): 520 Accepted Submission(s): 203
#include <stdio.h> #include <math.h> #include <iostream> #include <algorithm> #include <string.h> #include <stdlib.h> using namespace std; typedef long long LL; const int N = 100005; char str[N]; LL inv[10005]; ///逆元 LL num[N]; LL extend_gcd(LL a,LL b,LL &x,LL &y){ if( b == 0 ) { x = 1; y = 0; return a; } else{ LL x1,y1; LL d = extend_gcd (b,a % b,x1,y1); x = y1; y= x1 - a / b * y1; return d; } } LL mod_reverse(LL a,LL n) { LL x,y; LL d=extend_gcd(a,n,x,y); if(d==1) return (x%n+n)%n; else return -1; } void init(){ inv[0] = 0,inv[1]=1; for(int i=2;i<=10000;i++){ inv[i] = mod_reverse(i,9973); } } int main() { int m; init(); while(~scanf("%d",&m)){ scanf("%s",str+1); int len = strlen(str+1); num[1] = str[1]-28; for(int i=2;i<=len;i++){ int x = str[i]-28; num[i] = (num[i-1]*x)%9973; } while(m--){ int l,r; scanf("%d%d",&l,&r); if(l==1) printf("%d\n",num[r]); else printf("%lld\n",num[r]*inv[num[l-1]]%9973); ///(num[r]/num[l-1])%9973 } } }
标签:
原文地址:http://www.cnblogs.com/liyinggang/p/5517716.html