【模板】快速幂取模

快速幂取模的模板,要注意所有变量都要开成long long类型的防溢出:

#include<cstdio>
#include<algorithm>
#include<cstring>
typedef long long LL;
const LL mod=1e9+7;
using namespace std;
LL a,b;
LL mi(LL x,LL y)
{
    LL res=1;
    while(y){
        if(y&1)
            res=res*x%mod;
        y>>=1;
        x=x*x%mod;
    }
    return res;
}
int main()
{
    scanf("%lld %lld",&a,&b);//ÇóaµÄb´ÎÃÝ 
    printf("%lld",mi(a,b));
    return 0;
} 
快速幂取模模板
原文地址:https://www.cnblogs.com/JKAI/p/7403955.html