/*#include #include #include #include #include #include #include #include #include #include #include #define int long long #define INF 0X3F3F3F3F #define MOD 9973 #define N 100100 #define FF(i,a,b) for(int i=a;i<=b;++i) #define RR(i,b,a) for(int i=b;i>=a;--i) #define SC(x) scanf("%d",&x) #define SCC(x,y) scanf("%d%d",&x,&y) #define SCCC(x,y,z) scanf("%d%d%d",&x,&y,&z) #define SS(x) scanf("%s",x) #define PR(x) printf("%d\n",x) #define CL(a,b) memset(a,b,sizeof(a)) #define PB push_back #define SI sizeof() #define FIN freopen("in.txt","r",stdin) #define FOUT freopen("out.txt","w",stdout) using namespace std; const double PI=acos(-1.0); const double EPS=1e-8; int main(){ int i,j,_,n,m,x,y; char s[N]; int a[N]; while(~SC(n)){ SS(s); a[0]=1; for(int i=1;i<=strlen(s);++i){ a[i]=a[i-1]*(s[i-1]-28)%MOD; } FF(i,1,n){ SCC(x,y); int ans=1,x0,y0,gcd; exgcd(a[x-1],MOD,gcd,x0,y0); x0=(x0%MOD+MOD)%MOD; ans=a[y]*x0%MOD; PR(ans); } } return 0; } */ #include #include #include using namespace std; const int maxn=100005; const int mod=9973; int sum[maxn]; char s[maxn]; void exgcd(int a,int b,int &d,int &x,int &y){ if(!b)d=a,x=1,y=0; else{ exgcd(b,a%b,d,y,x); y-=x*(a/b); } } int inv(int a,int n) { int d,x,y; exgcd(a,n,d,x,y); return ((x+n)%n+n)%n; } int main() { int n; while(~scanf("%d",&n)) { scanf("%s",s+1); sum[0]=1; for(int i=1;s[i]!=0;++i) { sum[i]=(sum[i-1]*(s[i]-28))%mod; } for(int i=0;i