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;
}
一道需要注意角标的题
打表
快速幂求逆元
#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;
}
相关文章推荐
- hdu 5685 Problem A(2016"百度之星" - 资格赛(Astar Round1)——线段树)
- 2016"百度之星" - 资格赛(Astar Round1)Problem A & hdu 5685
- HDU 5685:2016"百度之星" - 资格赛 Problem A
- hdu 5688 2016"百度之星" - 资格赛 Problem D
- hdu 5688 Problem D (2016"百度之星" - 资格赛(Astar Round1)——Map存储)
- 2016"百度之星" - 资格赛(Astar Round1)
- hdoj 5687 2016"百度之星" - 资格赛Problem C【字典树--增--删--查】
- 2017"百度之星"程序设计大赛 - 资格赛 HDU 6083 度度熊的午饭时光
- 2016"百度之星" - 资格赛(Astar Round1)
- HDU 5690 All X(2016"百度之星" - 初赛(Astar Round2A))
- 2016"百度之星" - 资格赛(Astar Round1) Problem C
- 2016 百度之星资格赛题解(hdu 5685,5686,5687,5688,5689)
- HDU 5686:2016"百度之星" - 资格赛 Problem B
- 【快速幂+组合数+逆元】HDU5698瞬间移动【2016"百度之星" - 初赛(Astar Round2B)】
- 2016"百度之星" - 资格赛(Astar Round1)Problem B(大数加法)
- HDU 5688:2016"百度之星" - 资格赛 Problem D
- hdu 5698 瞬间移动(2016"百度之星" - 初赛(Astar Round2B)——数学题)
- HDU 5713 & 2016"百度之星" 复赛(Astar Round3)1002 k个联通块
- hdu 6081 度度熊的王国战略 2017"百度之星"程序设计大赛 - 资格赛 1002
- 2016"百度之星" - 资格赛(Astar Round1)Problem D