https://codeforces.com/contest/17/problem/D
没有前导零
因此一共写个数字,再mod c
数据范围很大,因此我们魔改一下快读
再用扩展欧拉定理
#include<iostream>
#include<cstdio>
#include<cstring>
using namespace std;
typedef long long ll;
string B,N;
ll c,mod;
ll phi(ll x){//欧拉函数ll res=x;for(int i=2;i<=x/i;i++){if(x%i==0){res=res/i*(i-1);while(x%i==0){x/=i;}}}if(x!=1){res=res/x*(x-1);}return res;
}
ll read(string s,int m,bool &ok){//魔改ll res=0;for(int i=0;i<s.size();i++){res=(res<<3)+(res<<1)+(s[i]-'0');if(res>m){res%=m;ok=1;}}return res;
}
ll qmi(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;
}
//(b-1)*qmi(b,n-1)
int main(){ios::sync_with_stdio(false);cin.tie(0),cout.tie(0);ll c;cin>>B>>N>>c;bool tt=0;ll b=read(B,c,tt);bool ok=0;ll n=read(N,phi(c),ok);ll t1=0;if(ok){t1=qmi(b,n-1+phi(c),c);}else{t1=qmi(b,n-1,c);}ll t2=((b-1)%c+c)%c;ll ans=t1*t2;ans=(ans+c)%c;if(!ans){ans=c;}cout<<ans<<'\n';return 0;
}