快速幂取余
#include<iostream> #define LL long long using namespace std; LL b,p,k; inline void quickM() { cin>>b>>p>>k; if(p==0) { cout<<b<<"^"<<p<<" "<<"mod"<<" "<<k<<"="<<1%k; return; } cout<<b<<"^"<<p<<" "<<"mod"<<" "<<k<<"="; LL ans=1; while(p!=0) { if(p&1!=0) ans=ans*b%k; b=b*b%k; p>>=1; } cout<<ans; } int main() { quickM(); return 0; }