您的位置:首页 > 其它

hdu 5685 2016"百度之星" - 资格赛(Astar Round1)Problem A

2017-07-31 23:12 429 查看
点这里

一道需要注意角标的题

打表

快速幂求逆元

#include <iostream>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <algorithm>
using namespace std;
const int mod=9973;
typedef long long ll;
ll an[100005];
char l[100005];
long long pow1(long long n,long long m )
{
long long ans = 1;
while(m > 0)
{
if(m & 1)ans = (ans * n) % mod;
m = m >> 1;
n = (n * n) % mod;
}
return ans;
}
int main()
{
int t;
while(cin>>t)
{
getchar();
cin>>l;
an[0]=1;
int len=strlen(l);
for(int i=1; i<=len; i++)
{
an[i]=(an[i-1]*((int)l[i-1]-28))%mod;
}
// cout<<an[11]<<endl;
for(int i=0; i<t; i++)
{
int x,y;
ll ans=1;
scanf("%d%d",&x,&y);
ans=an[y]*pow1(an[x-1]%mod,mod-2)%mod;
cout<<ans<<endl;
}

}
return 0;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: