快速幂取模模板

long exp_mod(long a,long n,long b)    //a为底数,n为幂数,b为余数
{
    long t;
    if(n==0) return 1%b;
    if(n==1) return a%b;
    t=exp_mod(a,n/2,b);
    t=t*t%b;
    if((n&1)==1) t=t*a%b;
    return t;
}

posted @ 2014-01-27 16:08  紫忆  阅读(238)  评论(0编辑  收藏  举报