首页 > 其他 > 详细

QuickPower快速幂

时间:2017-06-27 16:05:00      阅读:285      评论:0      收藏:0      [点我收藏+]

技术分享

#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 obb 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));
}

 

QuickPower快速幂

原文:http://www.cnblogs.com/mczhuang/p/7085590.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!