码迷,mamicode.com
首页 > 编程语言 > 详细

模板C++ 02数论算法 5快速幂及快速乘

时间:2017-06-06 14:16:17      阅读:142      评论:0      收藏:0      [点我收藏+]

标签:数论   span   c++   pre   style   return   amp   color   ret   

2.5快速幂及快速乘

int qmul(int x,int y)
{
    int s=0;
    while(y)
    {
        if(y&1) s=(s+x)%p;
        x=(x+x)%p;
        y>>1;
    }
    return s%p;
}
int qpow(int x,int y) { int s=1; while(y) { if(y&1) s=qmul(s,x); x=qmul(x,x); y>>1; } return s%p; }

 

模板C++ 02数论算法 5快速幂及快速乘

标签:数论   span   c++   pre   style   return   amp   color   ret   

原文地址:http://www.cnblogs.com/Zory/p/6951058.html

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