poj 1995 Raising Modulo Numbers ——快速幂
2013-04-02 17:47
375 查看
题目链接:http://poj.org/problem?id=1995 标准的快速幂的题目,唯一需要注意的就是:结果要用longlongint。开始不知道,第二个样例怎么也过不了,后来看了书上的代码才知道…… 其实应该想到要用LL的,这种错误应该自己查出来,题目中虽然没有说Ai,Bi的范围,但是保险起见,应该用LL啊。惭愧……
#include<iostream> #include<cstdio> #include<cstdlib> #include<cstring> #include<cctype> #include<stack> #include<queue> #include<cmath> #include<algorithm> #definelsonl,m,rt<<1 #definersonm+1,r,rt<<1|1 usingnamespacestd; typedeflonglongintLL; constintMAXN=0x3f3f3f3f; constintMIN=-0x3f3f3f3f; intm; LLpower(LLa,LLk){ LLans=1; while(k){ if(k&1){ ans=(ans*a)%m;k--; } k>>=1;a=(a*a)%m; } returnans; } intmain(void){ #ifndefONLINE_JUDGE freopen("1995.in","r",stdin); #endif intt;scanf("%d",&t); inta,b,h;LLans; while(t--){ scanf("%d%d",&m,&h); ans=0; while(h--){ scanf("%d%d",&a,&b); ans+=(power(a,b)%m); } ans%=m; printf("%lld\n",ans); } return0; }
有点儿乱……其实代码挺好写的
相关文章推荐
- poj 1995 Raising Modulo Numbers 快速幂取模
- POJ 1995-Raising Modulo Numbers-整数快速幂
- POJ1995 Raising Modulo Numbers(快速幂取模)
- POJ 1995 Raising Modulo Numbers (快速幂 +同余定理)
- poj 1995 Raising Modulo Numbers 二分快速幂
- 【POJ 1995】Raising Modulo Numbers(快速幂)
- POJ 1995 Raising Modulo Numbers【快速幂】
- POJ - 1995 - Raising Modulo Numbers - (快速幂)
- 【POJ】1995 - Raising Modulo Numbers 快速幂
- POJ1995 Raising Modulo Numbers【整数快速幂】
- poj1995 Raising Modulo Numbers【快速幂】
- POJ 1995 Raising Modulo Numbers(快速幂)
- poj 1995 Raising Modulo Numbers 【快速幂】
- |poj 1995|快速幂|Raising Modulo Numbers
- POJ1995:Raising Modulo Numbers(快速幂取余)
- poj 1995 Raising Modulo Numbers【快速幂】
- Poj1995 Raising Modulo Numbers(快速幂)
- Raising Modulo Numbers (poj 1995 快速幂水题)
- POJ 1995 Raising Modulo Numbers (快速幂模板)
- POJ1995 ZOJ2150 Raising Modulo Numbers【快速模幂】