#include
using namespace std;
long long int fun(long long int a,long long int b,long long int p)
{ //大数a*bmolp
long long int ans = 0;
int flag = 1;
if(a<0)
flag = -flag;
if(b<0)
flag = -flag;
while(b!=0)
{
if(b&1!=0)
{
ans = (ans+a)%p;
}
a = (a*2)%p;
b>>=1;
}
return ans;
}
int main()
{
long long int a,b,p;
cin>>a>>b>>p;
cout<