标签:play printf 分享 main style splay opened view mod
【算法】快速幂运算
【题解】快速幂的原理是把幂用二进制表示,从最低位a,次低位a2,次次低位(a2)2。
#include<cstdio> long long quick_pow(long long a,long long b,long long c) { long long ans=1; while(b>0) { if(b%2)ans=(ans*a)%c; b/=2; a=(a*a)%c; } return ans; } int main() { long long a,b,c; scanf("%lld%lld%lld",&a,&b,&c); printf("%lld",quick_pow(a,b,c)); return 0; }
标签:play printf 分享 main style splay opened view mod
原文地址:http://www.cnblogs.com/onioncyc/p/6916334.html