快速二分求幂 模板
2014-09-18 12:38
183 查看
#include<stdio.h>
#include<math.h>
#include<stdlib.h>
#include<string.h>
#include<iostream>
#include<algorithm>
using namespace std;
int Pow(int a,int b)
{
int ans=1;
while(b>0)
{
if(b%2==1)
ans*=a;
a*=a;
b>>=1;
}
return ans;
}
int main()
{
int A,B;
while(scanf("%d%d",&A,&B),(A||B))
printf("%d\n",Pow(A,B));
return 0;
}
#include<math.h>
#include<stdlib.h>
#include<string.h>
#include<iostream>
#include<algorithm>
using namespace std;
int Pow(int a,int b)
{
int ans=1;
while(b>0)
{
if(b%2==1)
ans*=a;
a*=a;
b>>=1;
}
return ans;
}
int main()
{
int A,B;
while(scanf("%d%d",&A,&B),(A||B))
printf("%d\n",Pow(A,B));
return 0;
}
相关文章推荐
- HDU 2035 人见人爱A^B(二分求幂,快速求幂)
- 九度OJ 1085 求root(N, k) -- 二分求幂及快速幂取模
- 快速排序模板和二分查找
- 算法 二分求幂(快速取幂)
- HDOJ 2035 人见人爱A^B-----二分快速求幂
- 九度OJ 二分求幂法、快速取模之《root(n,k)》
- Sumdiv(数论综合模板题:快速分解因式+快速幂取模+约数和公式+递归二分求等比数列和)
- [备战NOI同步赛]快速幂模板(二分/位运算)
- 二分求幂,快速求幂
- 二分求幂,快速求解a的b次幂
- poj3233(快速求幂+二分)
- hdoj 1588 矩阵快速幂 二分等比数列求和模板
- 判断素数+二分快速求幂——pku3641
- hdu 1005 Number Sequence(矩阵连乘+二分快速求幂)
- HDU 2035 人见人爱A^B(二分求幂,快速求幂)
- 九度OJ 1085 求root(N, k) -- 二分求幂及快速幂取模
- dp对组合数的预处理和快速幂取模模板
- 【结论】二分快速幂
- poj 3233 Matrix Power Series ——矩阵快速幂+二分求解
- 快速幂取模函数 递归模板