二分求幂

2017-07-20 17:47:25 

writer:pprp

介绍:二分求幂原理:

一般用递归求解:

代码如下:

int power(ll base,unsigned int exponent)
{
    if(exponent == 0)
    {
        return 1;
    }
    if(exponent == 1)
    {
        return base;
    }
    double result = power(base,exponent>>1);
    result *= result;
    if(exponent%2 == 1)
        result *= base;
    return result;
}

属于数论,遇到具体的题目还是有点问题

posted @ 2017-07-20 17:51  pprp  阅读(238)  评论(0编辑  收藏  举报