非递归快速幂

http://blog.csdn.net/zy691357966/article/details/39735701

int quickpow(int m,int n,int k)  
{  
    int b = 1;  
    while (n > 0)  
    {  
          if (n & 1)  
             b = (b*m)%k;  
          n = n >> 1 ;  
          m = (m*m)%k;  
    }  
    return b;  
}   

这里写图片描述

posted @ 2017-03-24 10:05  largecube233  阅读(70)  评论(0编辑  收藏  举报