#include <cstdio>
#include <cstring>
#include <cmath>
#include <iostream>
#include <algorithm>
#include <string>
#include <cstdlib>
using namespace std;
const int mod = 1e9+7;
typedef long long ll;
ll phi(ll n) //求欧拉函数值
{
int ans=n,temp=n;
for(int i=2;i*i<=temp;i++)
{
if(temp%i==0)
{
ans-=ans/i;
while(temp%i== 0) temp/=i;
}
}
if(temp>1) ans-=ans/temp;
return ans;
}
ll mod_pow(ll x,ll n,ll mod) //快速幂
{
ll ans=1;
while(n)
{
if(n%2==1) ans=ans*x%mod;
x=x*x%mod;
n/=2;
}
return ans;
}
ll a;
char b[1000010];
int main()
{
while(scanf("%lld%s",&a,b)!=EOF)
{
a%=mod;
ll phic=phi(mod);
int i,len=strlen(b);
ll res=0,ans;
for( i=0;i<len;i++)
{
res=res*10+b[i]-'0';
if(res>phic)
break;
}
if(i==len)
{
ans=mod_pow(a,res,mod)%mod;
}
else
{
res=0;
for(int i=0;i<len;i++)
{
res=res*10+b[i]-'0';
res%=phic;
}
ans=mod_pow(a,res+phic,mod)%mod;
}
cout<<ans<<endl;
}
return 0;
}
/*当你要计算 A^B%C的时候
因为此题中的B很大,达到10^100000,所以我们应该联想到降幂公式。
降幂公式:A^B%C = A^(B%phi© + phi©)%C
分两种情况:
当B<=phi©时,直接用快速幂计算A^B mod C
当B>phi©时,用快速幂计算A^(B mod phi©+phi©) mod C
*/
#include <cstdio>
#include <cstring>
#include <cmath>
#include <iostream>
#include <algorithm>
#include <string>
#include <cstdlib>
using namespace std;
const int mod = 1e9+7;
typedef long long ll;
ll phi(ll n) //求欧拉函数值
{
int ans=n,temp=n;
for(int i=2;i*i<=temp;i++)
{
if(temp%i==0)
{
ans-=ans/i;
while(temp%i== 0) temp/=i;
}
}
if(temp>1) ans-=ans/temp;
return ans;
}
ll mod_pow(ll x,ll n,ll mod) //快速幂
{
ll ans=1;
while(n)
{
if(n%2==1) ans=ans*x%mod;
x=x*x%mod;
n/=2;
}
return ans;
}
ll a,c;
char b[1000010];
int main()
{
while(scanf("%lld%s%lld",&a,b,&c)!=EOF)
{
c%=mod;
a%=mod;
ll phic=phi(mod);
int i,len=strlen(b);
ll res=0,ans;
for( i=0;i<len;i++)
{
res=res*10+b[i]-'0';
if(res>phic)
break;
}
if(i==len)
{
ans=mod_pow(a,res,mod)*c%mod;
}
else
{
res=0;
for(int i=0;i<len;i++)
{
res=res*10+b[i]-'0';
res%=phic;
}
ans=mod_pow(a,res+phic,mod)*c%mod;
}
cout<<ans<<endl;
}
return 0;
}