https://www.luogu.com.cn/problem/P1226
#include<bits/stdc++.h>
#define endl '\n'
#define pii pair<int,int>
using namespace std;
using ll = long long;
ll ksm(ll a,ll b,ll m)
{
ll ans=1;
while(b)
{
// 看当前二进制位是不是 1,是的话就乘上当前的权值
if(b&1) ans=ans*a%m;
a=a*a%m;
b>>=1;
}
return ans;
}
void solve()
{
int a,b,m;
cin>>a>>b>>m;
cout<<a<<'^'<<b<<" mod "<<m<<'='<<ksm(a,b,m)<<endl;
}
int main()
{
ios::sync_with_stdio(0),cin.tie(0),cout.tie(0);
int T; T=1;
while(T--)
solve();
return 0;
}