a的b次方模c

View Code
int fn2(int a,int b,int c){
    int result=1;
    int x=a%c;
    while(b>0){
        if(b%2){
            result=(result*x)%c;
        }
        x=(x*x)%c;
        b/=2;
    }
    return result;
}

 

posted @ 2012-12-23 12:40  sumaoqing123  阅读(216)  评论(0)    收藏  举报