【数论】【快速幂】CODEVS 2952 细胞分裂 2

裸快速幂取模,背诵模板用。

 1 #include<cstdio>
 2 using namespace std;
 3 typedef long long LL;
 4 LL n=1,m,q;
 5 LL Quick_Pow(LL a,LL p,LL MOD)
 6 {
 7     if(!p) return 1;
 8     LL ans=Quick_Pow(a,p>>1,MOD);
 9     ans=ans*ans%MOD;
10     if((p&1)==1) ans=ans*a%MOD;
11     return ans;
12 }
13 int main()
14 {
15     scanf("%lld%lld",&m,&q);
16     printf("%lld\n",Quick_Pow(2,m,q));
17     return 0;
18 }

 

posted @ 2014-10-27 08:59  AutSky_JadeK  阅读(170)  评论(0编辑  收藏  举报
TVアニメ「Charlotte(シャーロット)」公式サイト TVアニメ「Charlotte(シャーロット)」公式サイト