快速幂版版题....
时间复杂度 $O(log级别)$
C++ 代码
#include<bits/stdc++.h>
#define N 10010
#define INF 0x7fffffff
#define eps 1e-8
#define ll long long
using namespace std;
inline ll read(){
ll w=1,q=0;
char ch=' ';
while(ch!='-'&&(ch<'0'||ch>'9'))
ch=getchar();
if(ch=='-') w=-1,ch=getchar();
while(ch>='0'&&ch<='9')
q=q*10+ch-'0',ch=getchar();
return w*q;
}
inline ll Quick_pow(ll a,ll b,ll mod)
{
ll res=1;
while(b){
if(b&1)
res=(res*a)%mod;
a=(a*a)%mod;
b>>=1;
}
return res;
}
int main()
{
ll a,b,m,ans;
a=read(),b=read(),m=read();
if(!b){
ans=1;
printf("%d\n",ans%m);
return 0;
}
ans=Quick_pow(a,b,m);
printf("%lld\n",ans);
return 0;
}