用于指数爆longlong的情况,当然你也可以打高精……
因为昨天有人提到了慢速乘,感觉挺有用的,就顺便都学了吧,而且省选也用到十进制快速幂了。
#include<iostream>
#include<cstring>
#include<cstdio>
#define LL long long
using namespace std;
char c[100000];
LL a,p,t;
LL tenthpow(LL a)
{
LL ans=1,s=a;
while(t>=0)
{
LL cnt=c[t]-'0',cur=s;
for(int i=1;i<=cnt;i++)
ans=ans*s%p;
for(int i=1;i<10;i++)
cur=cur*s%p;
s=cur;ans%=p;t--;
}
return ans;
}
signed main()
{
cin>>a>>c>>p;
t=strlen(c);t--;
cout<<tenthpow(a)<<endl;
}