#include <bits/stdc++.h>
using namespace std;
//一般方法
int pow1(int a, int b)
{
int t = a;
b--;
while(b--)
a *= t;
return a;
}
//普通快速幂
int pow2(int a,int b)
{
int res = 1;
int base = a;
while(b > 0)
{
if(b % 2)
res *= base;
base *= base;
b /= 2;
}
return res;
}
//位运算快速幂
int pow3(int a,int b)
{
int r = 1, base = a;
while(b != 0)
{
if(b & 1)
r *= base;
base *= base;
b >>= 1;
}
return r;
}
int main()
{
int a, b;
while(printf("输入A^B中的A和B:"), cin >> a >> b)
{
printf("C语言函数:%d\n", (int)pow(a, b));
printf("一般方法:%d\n", pow1(a, b));
printf("普通快速幂:%d\n", pow2(a, b));
printf("位运算快速幂:%d\n", pow3(a, b));
printf("\n");
}
return 0;
}