#include <bits/stdc++.h>
using namespace std;
const int N=1e5+10;
typedef long long ll;
ll pt(ll a,ll n,ll p){
ll sum=1;
while(n){
if(n&1) sum=sum*a%p;
a=a*a%p;
n>>=1;
}
return sum;
}
int main(){
ll a,m;
string b;
cin>>a>>m>>b;
ll phi=m,temp=m;
for(int i=2;i*i<=m;i++){
if(temp%i==0){
phi-=phi/i;
while(temp%i==0) temp/=i;
}
}
if(temp>1) phi-=phi/temp;
ll s=0;
int f=0;
for(int i=0;i<b.size();i++){
s=s*10+(b[i]-'0');
if(s>=phi){
f=1;
s%=phi;
}
}
if(f) s+=phi;
cout<<pt(a,s,m);
return 0;
}
扩展欧拉定理(欧拉降幂)
最新推荐文章于 2024-06-15 23:36:03 发布