快速幂取模

    xiaoxiao2026-10-06  0

        大数的幂的取模,还是非常有用的,即a^n%MOD,废话不多说,直接上代码:

    #define LL long long int LL POW(LL a,LL n,LL MOD){ LL ret = 1; LL temp = a%MOD; while(n!=0){ if(n%2==1) ret = (ret*temp)%MOD; n = n/2; temp = (temp *temp)%MOD; } return ret; }     至于原理嘛,一大牛的博客 http://blog.csdn.net/y990041769/article/details/22311889

    转载请注明原文地址: https://ju.6miu.com/read-1312683.html
    最新回复(0)