分治策略解决幂乘问题

float fast_pow ( float x, float y ) {
 
    if ( y == 1 )
        return x;
 
    else if ( (int)y % 2 == 0 )
        return fast_pow(x,y/2)*fast_pow(x,y/2);
 
    else
        return fast_pow(x,(y-1)/2)*fast_pow(x,(y-1)/2)*x;
}
posted @ 2018-07-25 20:15  雪卿狂  阅读(1154)  评论(0编辑  收藏  举报