码迷,mamicode.com
首页 > 其他好文 > 详细

二分求幂

时间:2017-07-20 18:04:57      阅读:104      评论:0      收藏:0      [点我收藏+]

标签:log   com   result   div   ges   images   width   base   turn   

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;
}

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

二分求幂

标签:log   com   result   div   ges   images   width   base   turn   

原文地址:http://www.cnblogs.com/ilovelianghui/p/7212556.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!