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

 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 }

 

相关文章:

  • 2022-02-20
  • 2021-11-07
  • 2021-08-23
  • 2021-10-07
  • 2021-11-28
猜你喜欢
  • 2021-11-01
  • 2022-02-09
  • 2021-07-09
  • 2021-07-16
  • 2022-01-22
  • 2021-06-01
相关资源
相似解决方案