两个数相乘超long long乘法的取模

类似与快速幂的做法

View Code
/*===================================================================*\ 
| 两个数相乘超long long乘法的取模 mod的大小要十分注意
\*===================================================================*/
int multi_mod(int a,int b,int c) { //(a*b)%c 
    int ret=0;
    while(b) {
        if(b&1) { ret+=a; if(ret>=c) ret-=c; }
        a<<=1;  if(a>=c) a-=c;  b>>=1;
    }
    return ret;
} 

 

 

posted @ 2013-03-31 11:09  zhang1107  阅读(1735)  评论(0编辑  收藏  举报