快速幂求模模板:
#include<iostream> #include<cstdio> using namespace std; typedef long long LL; int main() { LL b,p,k; cin>>b>>p>>k; LL ans=1; LL x=p; LL y=b; while(p>0) { if(p&1) { ans=ans*b%k; } b=b*b%k; p=p>>1; } cout<<y<<"^"<<x<<" mod "<<k<<"="<<ans%k; return 0; }