#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cmath>
using namespace std;
typedef long long ll;
const int maxn=1200000+5;
inline int gcd(int a,int b){
if(!b) return a;
return gcd(b,a%b);
}
ll n,ans=1;
int a,k;
int c[maxn];
ll power(ll a,ll p){
ll res=1,base=a;
for(int i=p;i;i=i>>1,base=base*base%k)
if(i&1) res=res*base%k;
return res;
}
int main(){
scanf("%d%lld%lld",&a,&n,&k);
c[0]=1;
for(int i=1;i<=a;++i){
c[i]=gcd(i,a)%k;
c[i]=c[i]*c[i-1]%k;
}
ll tmp1=floor((double)n/(double)a);
ll tmp2=n%a;
ans=power(c[a],tmp1);
ans=ans*c[tmp2]%k;
printf("%lld",ans);
return 0;
}