- #include
- #include
- #include
- #defineLL long longusing namespace std;
- LL b,p,k,i,j;
- LL powe(LL m,LL n,LL c)
- {
- LL r=1,base=m;
- while(n)
- {
- if(n&1)
- r=r*base%c;
- base=base*base%c;
- n>>=1;
- }
- return r;
- }
- int main()
- {
- ios::sync_with_stdio(false);
- cin>>b;
- cin>>p;
- cin>>k;
- LL ans=powe(b,p,k);
- cout<"^"<" mod "<"="<<ans;
- }
来源: