欧拉降幂 (a^t)%c 模板
1 #include<bits/stdc++.h> 2 using namespace std; 3 typedef long long ll; 4 ll a,c,p,mod; 5 char t[1001]; 6 ll phi(ll n) 7 { 8 ll res=n; 9 for(int i=2;i*i<=n;i++){ 10 if(n%i==0){ 11 res=res/i*(i-1); 12 while(n%i==0) 13 n/=i; 14 } 15 } 16 if(n>1) 17 res=res/n*(n-1); 18 return res; 19 } 20 ll quickpower(ll a,ll b,ll c) 21 { 22 ll ans=1; 23 while(b) 24 { 25 if(b&1) 26 ans=(ans*a)%c; 27 a=(a*a)%c; 28 b>>=1; 29 } 30 return ans; 31 } 32 int main() 33 { 34 while(~scanf("%lld%s%lld",&a,t,&c)){ 35 int len=strlen(t); 36 ll p=phi(c); 37 ll ans=0; 38 for(ll i=0;i<len;i++) 39 ans=(ans*10+t[i]-'0')%p; 40 ans+=p; 41 printf("%lld\n",quickpower(a,ans,c)); 42 } 43 }