QuickPower快速幂

#include <iostream>
#include <cstdio>
using namespace std;
int a,b;
long long qp(int a,int b)
{
    int t=1;int y=a;
    while (b)
    {
        if (b&1) t=t*y;//whether odd or not
        y=y*y;
        b=b>>1;
        //cout << a << " " << b << " " << t << " " << y << endl;
    }
    return(t);
}
int main()
{
    scanf("%d %d",&a,&b);
    printf("%lld",qp(a,b));
}

 

posted @ 2017-06-27 15:49  Michael_Zhuang  阅读(177)  评论(0编辑  收藏  举报